Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
create commit and push to repo during CI build in gitlab
- generate ssh key for gitlab-runner user
- add ssh key to project's deploy keys (project/setting/repository)
add below commands into script section of .gitlab-ci.yml file.
# CI_REPOSITORY_URL contains gitlab-ci-token. replace start of the string up to '@' with git@' and append a ':' before first '/'
# example
# CI_REPOSITORY_URL=https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@example.com/gitlab-examples/ci-debug-trace.git
# should be git@example.com:/gitlab-examples/ci-debug-trace.git
- export PUSH_REPO=$(echo "$CI_REPOSITORY_URL" | sed -e "s|.*@\(.*\)|git@\1|" -e "s|/|:/|" )
# gitlab-runner runs on a detached HEAD, checkout a new branch
- git checkout -b lock
#generate & save dependencies.lock file
- gradle generateLock saveLock
# commit dependencies.lock file. add '[skip ci]' into commit message to prevent CI infinite loop
- git commit -m '[skip ci] add auto generated dependencies.lock' dependencies.lock
# set remote push URL
- git remote set-url --push origin "${PUSH_REPO}"
# push changes to originating branch
- git push origin lock:${CI_COMMIT_REF_NAME}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.