admin管理员组文章数量:1123650
we use the GitLab-CI for our building/testing envorinment. The system is Ubuntu and the git version is 2.25.1. I tried to update the git version, but appareantly no more recent version is available for this distribution. Because of technical reasons the working directory of the gitlab-runner is not where the code under test is, so we have a manual step for switching the branch in the target directory to the desired git branch.
The job looks like this:
script:
- cd <target-directory>
- git reset --hard origin/master
- git clean -d -f .
- git pull :$BOT_SSO@<my-repository>.git $BRANCH
- git status
What i thought it does is to switch to the target directory, reset whatever there is to the last known master state and clean up surviving untracked files. Afterwards i want to get and switch to the desired branch and check the state now.
What it actually does is appareantly to just get the files from the desired branch but not switching to it. The log looks like this:
$ cd <target-directory>
$ git reset --hard origin/master
HEAD is now at 08d09b4 <Commit-Message>:
$ git clean -d -f .
$ git pull <repository> $BRANCH
From <repository>
* branch <desired-branch> -> FETCH_HEAD
Updating 08d09b4..46ba060
Fast-forward
... changes
$ git status
On branch master
nothing to commit, working tree clean
Cleaning up project directory and file based variables
00:00
Job succeeded
So this job changes files but does not change the branch.
If i alter the script like this:
script:
- cd <target-directory>
- git reset --hard origin/master
- git clean -d -f .
- git pull :$BOT_SSO@<my-repository>.git
- git checkout $BRANCH
- git status
I get an error:
$ cd <target-directory>
$ git reset --hard origin/master
HEAD is now at 8d47e28 <commit-message>
$ git clean -d -f .
$ git pull <repository>
From <repository>
* branch HEAD -> FETCH_HEAD
Updating 8d47e28..08aa112
Fast-forward
... file changes
11 files changed, 45 insertions(+), 78 deletions(-)
$ git checkout $BRANCH
error: pathspec '<branch name>' did not match any file(s) known to git
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit status 1
So it looks like the branch i want to checkout it is unkown to git. I also tried to replace pull with fetch but the result remains the same. I also observed if i update the master branch with the statement above, the 'reset origin/master' resets it not to the current state of the master branch remote, but to the last known state locally.
Does anyone know how to fix this?
本文标签: Try to checkout git branch with gitlab ci job does not work as expectedStack Overflow
版权声明:本文标题:Try to checkout git branch with gitlab ci job does not work as expected - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736582898a1944970.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论