1

The master branch has a folder that contains a loader (groovy) script which is run using a Jenkins pipeline.

                sh """
                set +x
                export JAVA_OPTS='--illegal-access=deny'
                source /var/lib/jenkins/.sdkman/bin/sdkman-init.sh
                sdk install groovy || true
                sdk use java 11.0.7.hs-adpt || true
                cd jenkins/loader
                groovy <script_name> 

Part of the script is reproduced above. The last two lines is for navigating to the script folder in the master branch and executing the groovy script. The script loads some files from the master branch into the target environment. However, the requirement is to load the files from a release branch instead of master branch. How can this be achieved? Thanks

  • 1
    As far as *Git* is concerned, to "load files" from some particular commit, you'll need to extract those files from that commit. Consider running `git archive` to do that, since that gives you a convenient way to extract just the files in some sub-directory as a tar or zip archive, which you can then un-tar or un-zip. You will need access to a clone of the Git repository that has the desired commit. How you get that in *Jenkins* is a Jenkins question, not a Git question. – torek Sep 06 '21 at 16:48

1 Answers1

0

Assuming the Jenkins job has checked out the master branch, the first step in that job/pipeline would be to restore one file from another branch:

git restore --source release -- jenkins/loader/script_name

Then the rest of your job/pipeline can proceed, since the Jenkins job workspace now include the right version of that script.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250