0
votes

I have a multibranch pipeline in Jenkins. I want to include my script file (jenkinsfile) as svn file external into my development branches to organize the script centralized for all branches. Unfortunately the scan of the multibranch pipeline isn't able to find the script file as it is only looking inside the declared branch and not in the included svn external locations. Has anyone an idea how can I fix this?

Below is an example of my svn structure, job config and further information.


SVN:

root/
    scripts/
        jenkinsfile
    code/
        version1/
            branchX/
            ...
        version11/        
            branchY/
            ...

SVN external property for branchX, branchY, etc.

Local path:   jenkinsfile
URL:          ^/scripts/jenkinsfile
Revision Peg: 12345

Multibranch job configuration:

Subversion
    Project Repository Base: http://.../root/code/
    Include branches:        version1/branchX, version11/branchY
Build configuration
    Mode:        by Jenkinsfile
    Script path: jenkinsfile

Log message of scan in multibranch pipeline:

...
Checking candidate branch /code/version1/branchX@HEAD
      ‘jenkinsfile’ not found
Does not meet criteria
...

I already tried to disable the lightweight checkout of the subversion scm plugin according to this advice: Multibranch pipeline with jenkinsfile in svn:external (I've added -Djenkins.scm.impl.subversion.SubversionSCMFileSystem.disable=true under <service><arguments>... in jenkins.xml)

But jenkins is still not able to find the script. And in fact if I put my script directly in e.g. branchX the disabled lightweight checkout leads to a double checkout into my workspace (first one to read the script file and second one as it's my first stage in the script itself).

Maybe my whole setup is wrong too or not the ideal way of doing?

I would be pleased about your help and tips. Thanks and Greetings!

1

1 Answers

0
votes

If you are working on a linux or bsd(osx) system, you could create a hard-link from root/scripts/jenkinsfile to root/code/version#/branchX/jenkinsfile for each active branch

That way, each branch will have its own jenkinsfile available locally, enabling you to use the lightweight checkout, and any change you introduce to the jenkinsfile in any location will be available to all other branches (the file system will keep a single copy of the file, regardless of being accessible form many different locations).

The bash command to create such link will be

ln root/scripts/jenkinsfile root/code/version#/branchX/jenkinsfile

You will need to remember to create a new link each time a branch is created, or automate that using hooks