Home > Back-end >  How to execute a shell script file in a particular branch in a gitlab job script?
How to execute a shell script file in a particular branch in a gitlab job script?

Time:10-12

The script.sh is in a particular branch and not in master, so how do I specify in the script identifier to locate the file in that branch.

build_job:
stage: build
script:
  - ./project/config/script.sh > job.yml

CodePudding user response:

If you want to swap branches during a pipeline job, then you will need to:

  1. Set up authentication in the before_script using HTTPS or SSH method,
  2. In the script section, add the standard git commands, such as git checkout, to get to the correct branch,
  3. Then have your script run.

Just keep in mind that if you've checked out the branch it's on, the job is using that branch. So, if you want to run the script against the current branch or commit, you'll have to copy the file to a temporary location that the job can access, then switch to the current branch/commit again to run the script against.

  • Related