首页 > 解决方案 > Git 使用 jenkins 管道拉取远程服务器

问题描述

我有这个用于 git checkout 阶段,它工作正常

checkout([$class: 'GitSCM',
     branches: [[name: "*/master" ]],
     doGenerateSubmoduleConfigurations: false,
     extensions: [[$class: 'LocalBranch', localBranch: "**"]],
     submoduleCfg: [],
     userRemoteConfigs: [[credentialsId: env.GIT_CREDS, url: env.GIT_REPO]]
         ])

我正在尝试配置 jenkins 作业(使用 jenkins 管道)以使用 sshagent 在远程服务器上执行git pull 需要使用管道中为远程服务器上的 git pull 定义的GIT_CREDS需要类似:

sh "ssh ubuntu@$Ip 'git pull'" 

使用GIT_CREDSGIT_REPO 环境变量

有人可以帮我解决这个问题吗

标签: gitjenkinsjenkins-pipelinessh-agent

解决方案


只需使用 git

git(
    url: 'git@git.com:YourGitRepo.git',
    credentialsId: '5ef933f28-bdb2-0563-bfc7-b460490262735', // found here http://jenkinsURL:8080/credentials/
    branch: 'master'
    )

它在内部使用 ssh。
希望能帮助到你 :)


推荐阅读