Created
October 17, 2017 12:24
-
-
Save serdroid/7bd7e171681aa17109e3f350abe97817 to your computer and use it in GitHub Desktop.
create commit and push to repo during CI build in gitlab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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:[email protected]/gitlab-examples/ci-debug-trace.git | |
# should be [email protected]:/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