我在 CI 管道中的存储库的分离头方面遇到了一些问题。在管道的构建阶段,我运行一个脚本,该脚本更改特定文件。更改此文件后,将其推送到存储库。
before_script:
- git config --global user.name "Bot"
- git config --global user.email "ci@domain.com"
- git status
script:
- npx ts-node ./generate.ts
- git push "https://git:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@}" "HEAD:main"
- git status
Run Code Online (Sandbox Code Playgroud)
运行脚本给我输出
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/fKSu5-y_/0/project/.git/
Created fresh repository.
Checking out 9b4a88be as main...
$ git status
HEAD detached at 9b4a88be
$ git push "https://git:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@}" "HEAD:main"
To https://gitlab.domain.com/project.git
9b4a88b..98be83e HEAD -> main
$ git status
HEAD detached from 9b4a88b …Run Code Online (Sandbox Code Playgroud) 在我的CI管道中,我正在生成一个public/graph.png可视化我的代码某些方面的工件。在以后的步骤中,我想将其从CI管道中提交给仓库。这是相关的部分.gitlab-ci.yml:
commit-graph:
stage: pages
script:
- git config user.email "cipipeline@example.com"
- git config user.name "CI Pipeline"
- cd /group/project
- mv public/graph.png .
- git add graph.png
- git commit -m "committing graph.png [ci skip]"
- echo $CI_COMMIT_REF_NAME
- git push origin HEAD:$CI_COMMIT_REF_NAME
Run Code Online (Sandbox Code Playgroud)
当管道在gitlab中运行时,它失败并显示:
$ git config user.email“ cipipeline@dhgitlab.dunnhumby.co.uk”
$ git config user.name“ CI管道”
$ cd / group / project
$ mv public / graph.png。
$ git add graph.png
$ git commit -m“ committing graph.png [ci …