当前位置: 代码迷 >> 综合 >> Jenkins GitLab 集成代码下载部分
  详细解决方案

Jenkins GitLab 集成代码下载部分

热度:77   发布时间:2023-09-30 12:47:06.0

代码下载部分


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

Jenkins GitLab 集成代码下载部分

Jenkins GitLab 集成代码下载部分

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 集成代码下载部分

Jenkins GitLab 集成代码下载部分

Jenkins GitLab 集成代码下载部分Jenkins GitLab 集成代码下载部分

 Jenkins GitLab 集成代码下载部分

Jenkins GitLab 集成代码下载部分

Jenkins GitLab 集成代码下载部分每个项目的代码库地址是不一样的,可以从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 anystages {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 集成代码下载部分