0

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!

j_d
  • 19
  • 1
  • 7

1 Answers1

0

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

matus
  • 703
  • 3
  • 13
  • That seems to be more like a "work-around" for me. It would be nice to manage that connection via svn external. That way, I could branch future new directories from trunk/old versions and still have a valid svn external link. Additionally I'm not able to access the linux server running svn. – j_d Jan 30 '20 at 15:51
  • I'm noticing that in your svn:externals definition, you seem to be defining a file, instead of a directory. Have you tried defining the `scripts` directory as svn:external, and then change the pipeline configuration in Jenkins to look for the Jenkinsfile in `scripts/jenkinsfile`? ... You can check if svn:externals is working as expected by cloning the repo locally in a new folder and see whether the `jenkinsfile` is in the desired place or not. – matus Jan 31 '20 at 11:16
  • A file as svn:external is possible since svn version 1.6 and it works. I already checked it by cloning a repo locally. In Jenkins I configured the subversion scm plugin to use svn version 1.8, so it should be no problems there. And yes I tried to link the whole folder als svn:external too, but jenkins multibranch scan is still not able to find the script. – j_d Jan 31 '20 at 11:49