36
loading...
This website collects cookies to deliver better user experience
GITLAB_PUSH_TOKEN
. With the above assumptions, you need to set the variable not to be protected - it has to be available on non-main branches. I recommend you make it masked - it will still be available for people who have access to this setting page, but at least your key will not appear in the job logs.stages:
- test
test
following what would make sense in the lint changes use case.add-commit:
stage: test
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: never
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
when: manual
script:
- echo 'test' >> $CI_COMMIT_BRANCH
- git add .
test
into the file named after the branch.- git status
- git -c user.email="$GITLAB_USER_EMAIL" -c user.name="$GITLAB_USER_NAME" commit -m "add change in $CI_PIPELINE_ID"
-c user. ...
- sets git configuration for the command alone. Feels cleaner to me than calling git config --global ...
, even though the context in which it would be run is discarded immediately after the job is done.commit ...
is already a standard commit call, but it has to be after the configuration was set
- git push "https://gitlab-ci-token:[email protected]/marcin-wosinek/automated-commit.git" HEAD:$CI_COMMIT_BRANCH
git push https://gitlab-ci-token:$GITLAB_PUSH_TOKEN
pushes with the token read from $GITLAB_PUSH_TOKEN
we defined earlier. Any configuration mismatch will fail here.gitlab.com/marcin-wosinek/automated-commit.git
- of course, you will need to replace marcin-wosinek
with your username/organization & `automated-commit with your project name. If you use a different GitLab server, it should be set here as well.HEAD:$CI_COMMIT_BRANCH
- the CI is in the detached HEAD state - there is no current branch. To work around it, I'm explicitly setting what branch I'm pushing to.
`yml