Skip to content

Instantly share code, notes, and snippets.

@serdroid
Created October 17, 2017 12:24
  • Star 23 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save serdroid/7bd7e171681aa17109e3f350abe97817 to your computer and use it in GitHub Desktop.
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