I have a job which creates builds with "sudo" or root privileges. Hence, when directory cleanup occurs at the start of a job run in GitLab CI-CD pipeline, I get the error as "Permission denied" while cleaning repository items.
I tried implementing a command with sudo rm -r *
in after_script
, but turns out the artifacts are uploaded after scripts are executed in following order:
before_script
script
after_script
artifacts uploading
What am I trying to achive:
I am in search of a way to clean the project directory after the artifacts are uploaded.
OR
If I could specify cloning of the repository into a particular(custom) directory.
I am fairly new to Gitlab Pipelines. Any help will be appreciated!
I figured out a way to solve this issue. Posting here the solution in case anyone faces similar issue.
There are certain set of commands which I wanted to execute after the job runs correctly and before cloning of git repository for another job on same build server. I achieved it by doing the following:
In /etc/gitlab-runner/config.toml
add pre_clone_script
key as below:
pre_clone_script = "<your commands here - for ex: sudo rm *>"
This script runs before cloning of the git repository takes place.