How to deploy the artifact of a CI?

Hi all,

I am practically a novice to CI. I have a very simple block of code for CI that generates output.pdf, and at the last step I manage to keep output.pdf as an artifact:

    artifacts:
        expose_as: 'output'
        paths:
             - output.pdf

But I actually want to push this output.pdf back to the repository easily visible once the pull request succeeds. I would deeply appreciate if somebody could direct me in the correct way, at least by telling me what the proper jargon for what I am asking so that I can search.

Thanks in advance

1 Like

Hi @tuncK,

do you want to commit output.pdf to your repository, like you would commit a file during development?

Sarah

Exactly. Committing output.pdf to the repository is indeed what I would like.

If impossible, a static URL to the artifact might also work, I can write a simple HTML pageforwarding to this URL.

In the settings for your project, add a CI variable (which should be masked) called TOKEN and set it to hold a Personal Access Tokens. You can create a PAT in your personal settings (not the settings for the project!).

Then, to make the actual commit, do something like this in your .gitlab-ci.yml:

git config --global user.name "${GITLAB_USER_NAME}"
git config --global user.email "${GITLAB_USER_EMAIL}"

git add output.pdf
git commit -m "Updated output.pdf"

# You might want to pull --rebase here just in case someone else has pushed to this branch?

git push http://${GITLAB_USER_LOGIN}:${TOKEN}@gitlab.com/path/project master  ${CI_COMMIT_BRANCH}

You might want to make this a bit more sophisticated. For example, to ensure that it doesn’t perform the commit/push when the pipeline is started by a tag rather than a commit, but hopefully this will give you a starting point.

You can see the list of available pre-defined variables that are available in pipelines on this page.

HTH,

Sarah

1 Like

Thanks a lot. Indeed this is what I have been looking for. Solved like a magic. I modified the last line as:

git push http://${GITLAB_USER_LOGIN}:${TOKEN}@gitlab.com/path/project HEAD:master
2 Likes

Awesome! Thanks for working together to get a solution! This will help many others in the future! :sparkles: