0
点赞
收藏
分享

微信扫一扫

Jenkins GitLab 集成代码下载部分


代码下载部分

找一个pipeline 类型的项目进入流水线语法, 找到片段生成器中的 ​​checkout​​ 。 我们使用checkout方法来进行代码下载(svn也是支持的哦) 

Jenkins GitLab 集成代码下载部分_生成器

Jenkins GitLab 集成代码下载部分_svn_02

checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: '655050bf-da7e-4ca6-85f3-3fb03b2155ad', url: 'http://139.198.166.235:81/devops/devops-hello-service.git']]])

 这样在那个分支提交就会下载哪个分支的代码了

Jenkins GitLab 集成代码下载部分_svn_03

Jenkins GitLab 集成代码下载部分_git_04

Jenkins GitLab 集成代码下载部分_git_05

Jenkins GitLab 集成代码下载部分_svn_06

 

Jenkins GitLab 集成代码下载部分_生成器_07

Jenkins GitLab 集成代码下载部分_svn_08

Jenkins GitLab 集成代码下载部分_生成器_09

每个项目的代码库地址是不一样的,可以从gitlab里面信息获取到,,这些都是自动触发获得的,要是手动触发就拿不到了。

拿到project下面的git_http_url

  "project": {
"id": 3,
"name": "devops-hello-service",
"description": "",
"web_url": "http://76c03cb0fea1/devops/devops-hello-service",
"avatar_url": null,
"git_ssh_url": "git@76c03cb0fea1:devops/devops-hello-service.git",
"git_http_url": "http://76c03cb0fea1/devops/devops-hello-service.git",
"namespace": "devops",
"visibility_level": 0,
"path_with_namespace": "devops/devops-hello-service",
"default_branch": "master",
"ci_config_path": null,
"homepage": "http://76c03cb0fea1/devops/devops-hello-service",
"url": "git@76c03cb0fea1:devops/devops-hello-service.git",
"ssh_url": "git@76c03cb0fea1:devops/devops-hello-service.git",
"http_url": "http://76c03cb0fea1/devops/devops-hello-service.git"
},

def credentialsId = "655050bf-da7e-4ca6-85f3-3fb03b2155ad"


webHookData = readJSON text: "${webHookData}"
env.userName = webHookData["user_username"]
env.userEmail = webHookData["user_email"]
env.branchName = webHookData["ref"] - "refs/heads/"
env.commitID = webHookData["checkout_sha"]
env.git_http_url = webHookData["project"]["git_http_url"]

currentBuild.displayName = env.commitID
currentBuild.description = "Trigger by user ${env.userName} \n branch: ${env.branchName}"


pipeline {
agent any

stages {
stage('CheckOut') {
steps {
println("project git url is ${git_http_url} ")
checkout([$class: 'GitSCM',
branches: [[name: "${env.branchName}"]],
extensions: [], userRemoteConfigs:
[[credentialsId: "${credentialsId}",
url: "${env.git_http_url}"]]])
}
}
}
}

 

Jenkins GitLab 集成代码下载部分_git_10

举报

相关推荐

0 条评论