Jenkins GitLab 集成代码下载部分

代码下载部分


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

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']]])

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

 

每个项目的代码库地址是不一样的,可以从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}"]]])
            }
        }
    }
}

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值