简体   繁体   English

试图在 gitlab 管道中推回

[英]Trying to push back in gitlab pipeline

I am new to ci processes.我是 ci 流程的新手。 But I ran into the following: when I create a new version of the package, during the execution of the pipeline, it updates the record in the file.但是我遇到了以下情况:当我创建新版本的 package 时,在管道执行期间,它会更新文件中的记录。 I need to do a git push, but I ran into different problems and got confused about which tokens to use.我需要做一个 git 推送,但我遇到了不同的问题并且对使用哪些令牌感到困惑。 We have our own server with gitlab, which runs pipelines.我们有自己的服务器 gitlab,它运行管道。

function try_push_back() {
  git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@$CI_SERVER_HOST/$CI_PROJECT_PATH.git
  cd "$CI_PROJECT_NAME"

  git config --global user.email "${GITLAB_USER_EMAIL}"
  git config --global user.name "${GITLAB_USER_NAME}"

  echo "$CI_JOB_ID" > output.txt
  git add output.txt
  git commit -m "[skip ci] Updating output.txt with latest CI_JOB_ID." >&2

  git push "http://${PERSONAL_USERNAME}:${PERSONAL_ACCESS_TOKEN}@$CI_SERVER_HOST/$CI_PROJECT_PATH.git" HEAD:"$CI_COMMIT_REF_NAME" >&2
}

With following code i have the next result:使用以下代码,我得到下一个结果:

result结果

I can fix it myself.我可以自己修。 Following code is work for me.以下代码对我有用。

  echo "committing version number to sfdx-project.json" >&2
  git remote set-url origin "https://gitlab-ci-token:$PERSONAL_ACCESS_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git"
  git config --global user.email "${GITLAB_USER_EMAIL}"
  git config --global user.name "${GITLAB_USER_NAME}"
  echo "$CI_JOB_ID" > output.txt
  git add output.txt
  git commit -m "[skip ci] Updating output.txt with latest CI_JOB_ID." >&2
  git status
  git push origin HEAD:"$CI_COMMIT_REF_NAME" >&2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM