I am new to ci processes. 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. I need to do a git push, but I ran into different problems and got confused about which tokens to use. We have our own server with gitlab, which runs pipelines.
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:
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