因此,我使用了Jenkins groovy脚本管道和一些shell脚本来检出代码存储库。然后运行一些测试,打包代码,然后将其用于切换到新文件夹并签出第二个git存储库。
到目前为止很好,真的很简单:
git url: 'git@gitlab:platform-automation.git', credentialsId: '12345678', branch: "${gitbranch}"
这曾经(根据作业日志)使用“ git checkout -b功能/新分支”签出新分支
最近对代码进行了重构,以使其可以向GitLab报告一些构建状态,现在不再检出分支:
Cloning repository git@gitlab:platform-automation.git
> git init /var/lib/jenkins/workspace/Package-for-Deployment/platform # timeout=10
Fetching upstream changes from git@gitlab:platform-automation.git
> git --version # timeout=10
using GIT_SSH to set credentials This key is used to access GitLab repositories
> git fetch --tags --progress git@gitlab:platform-automation.git +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url git@gitlab:platform-automation.git # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url git@gitlab:platform-automation.git # timeout=10
Fetching upstream changes from git@gitlab:platform-automation.git
using GIT_SSH to set credentials This key is used to access GitLab repositories
> git fetch --tags --progress git@gitlab:platform-automation.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/feature/new-branch^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/feature/new-branch^{commit} # timeout=10
> git rev-parse origin/feature/new-branch^{commit} # timeout=10
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
我认为我们可以使用git revert返回旧代码,结果很奇怪。
因此,请尝试删除$ {gitbranch}变量并使用它:
git url: 'git@gitlab:platform-automation.git', credentialsId: '12345678', branch: 'develop'
然后在下一行中,在shell脚本中添加一行,内容如下:
git checkout -b ${gitbranch}
现在,新分支已签出,并且作业按预期进行。
为什么Jenkins git管道插件现在在使用变量检出分支时出现问题?