Multibranch pipeline with jenkinsfile in svn:external - jenkins

I have set up a multibranch pipeline job for a repository in SVN. Since I want to keep the jenkinsfiles the same in all branches, they are not really located in the branches, but in a different location and only referenced via svn:externals.
Unfortunately the multibranch pipeline does not seem to follow these references and doesn't find the jenkinsfiles (the paths are correctly set):
Checking candidate branch /branches/aaa/bbb/ccc#HEAD
‘ddd\eee\fff\jenkinsfile' not found
Does not meet criteria
Is there any way to tell Jenkins and the multibranch-pipeline plugin setup to also follow svn:externals when looking for the jenkinsfiles?

By default, Jenkins is trying to get the Jenkinsfile with a lightweight checkout which does not consider svn:externals.
This behavior can be (only generally) deactivated, see https://wiki.jenkins.io/display/JENKINS/Subversion+Plugin, chapter "lightweight checkout capability for Subversion on Multibranch Pipeline projects and Externals support"

Related

Jenkins Pipeline from SCM. Can we select branch

We have our pipelines groovy scripts for Jenkins in SCM (git). I believe it currently gets the scripts from master as default.
Are we able to specify the branch we want to use for the groovy scripts?
There is a setting in the particular section but that seems to be for build branch if I understand correctly (as it allows for setting of multiple branches)
It appears that the branch option is the branch for the pipeline script.
I assume that multiple branches means you can run multiple branches of the different versions of that script. I suspect I am missing when that would be used but it does answer my original question.

How to migrate from Jenkinsfile to pipeline_config.groovy which uses JTE?

I'm in the process of migrating git-based projects to use a shared Pipeline definition from a governance tier built with Jenkins Templating Engine.
In the process of testing I cloned the project and pushed it to a new repository in Bitbucket where it was recognized by Jenkins and the template was used immediately based on the definitions in pipeline_config.groovy. However, this is not a sane migration path for existing projects. How do I get Jenkins to start using the template on branches without Jenkinsfile and the Jenkinsfile on branches with a Jenkinsfile.
The result of of "Scan Multibranch Pipeline Now" according to the logs is ‘Jenkinsfile’ not found. Skipping. I assume that a new project regonizer is provided by the Jenkins Templating Plugin.
I assume that every project with Git Flow has to perform this migration, so I'm confused there's no documentation.
I'm using Jenkins 2.306 and JTE plugin 2.3.
It seems that newer versions of JTE or Jenkins allow a mixture of branches with JTE and without.
In case you have to deal with versions that don't do the following:
Once I removed Jenkinsfile from every branch and put a pipeline_config.groovy on every branch the Multibranch Plugin started recognizing the project first as removed and at the next scan as present with all branches which were all using the Jenkins Template Engine.
Not the best migration imo, but a great opportunity to cleanup old branches. Since my project was using Git Flow I needed to make a technical hotfix release to also migrate away from Jenkinsfile on master.

Jenkins Multibranch Pipeline Lightweight Checkout

The Jenkins Pipeline plugin has a feature known as "lightweight checkout", where the master only pulls the Jenkinsfile from the repo, as opposed to the entire repo. There's a corresponding checkbox in the configuration screen. I'd like to do a lightweight checkout in a multibranch pipeline, but I'm not seeing a checkbox in the multibranch configuration screen. Any ideas how to make this happen? I noticed some closed issues that suggest this feature is available, but I wasn't able to find any specifics on how to make it happen.
Related information:
https://issues.jenkins-ci.org/browse/JENKINS-42518
https://issues.jenkins-ci.org/browse/JENKINS-33273
https://github.com/jenkinsci/bitbucket-branch-source-plugin/pull/78
I asked the developer, Vivek Pandey, who added the lightweight checkout feature to the multibranch plugin and he said that's the default behavior for the multibranch pipeline. Here's his response:
For multi-branch pipeline project GitHub or Bitbucket light weight checkout is default behavior. With bitbucket it wasn’t and that’s what my PR fixed. So basically you don’t need to do any configuration, it should work out of the box.

Jenkins Pipeline - How to maintain over time

I am currently using Cloudbees Jenkins Coreas my Jenkins solution.
I am using Jenkins Pipelines to write our Jenkins job configuration. These pipelines are stored in GitHub repositories. Each Jenkins job when created is connected to a GitHub Repository where the source code is pulled from, and that's where the Jenkinsfile is stored and Jenkins reads from.
Below are some high-level photos for how our Jenkins jobs are configured.
The advantage of the way these jobs are configured is the Jenkinsfile is always read from the master branch. Meaning if a rouge developer tries to remove stages from the Jenkinsfile from within there own branch, it doesn't matter because the Jenkinsfile is always read from the master branch (which is always protected).
However, the one massive drawback to this - is how do teams and developers who are devops engineerings make changes to the Jenkinsfile? For example, let's say a developer creates a branch called feature-jenkins-search and they edit the Jenkinsfile adding a new stage in the pipeline. Whenever they push these changes to GitHub to test - they can't test as it's always read from the master branch? Meaning devops engineerings have to work directly on the master branch? Surely this is not the best way to go and there is a better configuration to set?
We do want to still provide the security that if a developer is rougue and
You should really look into the Jenkins multi-branch pipeline feature. The Jenkins multi-branch pipeline allows to create a single configuration item in Jenkins (a bit like a folder) that can detect all the branches and pull requests in a GitHub repository with a Jenkinsfile and build them using automatically created jobs. Inside this multi-branch pipeline object when it is configured in Jenkins, you will find a number of jobs to build the various branches and pull-requests in the GitHub repository.
So your developers should maintain a Jenkinsfile in every branch they work on in GitHub to build that branch in your Jenkins server.
It is possible to make the Jenkinsfile do branch specific handling if required with conditional stages / when conditions in the Jenkinsfile pipelines in each branch.
You can lock down the master branch so that code and Jenkinsfile changes from other branches can only be merged with an approved PR (pull request). There is good integration between Jenkins and GitHub such that you can configure the master branch to only allow a PR to be merged if the PR is buildable in Jenkins. So if developers add new stages / processing to a Jenkinsfile on a branch being merged to master, it should be validated so that builds of your master branch are not broken.
There is a lot of configurability in the Jenkins multi-branch pipeline object for detection and handling of branches and it may be necessary to experiment to get it right for what you need with your team. If you cannot find this feature in Jenkins, it is probably because the correct Jenkins pipeline and GitHub related plugins are not installed.
You could also have a look at a similar Jenkins feature called the Jenkins GitHub Organization Folder which allows to detect and build all repos and branches at a GitHub Organization level. But when starting out, I would suggest to look into the multi-branch pipeline at the single repo level first.
These features are discussed in the Jenkins pipeline documentation. We use these features with our internal GitHub and Jenkins server and it works very well.
I think you will find the idea of using a single Jenkinsfile in the master branch to be used for building all branches is unworkable, as you have seen!

Polling ignores commits in certain paths in multibranch pipeline

I have a multibranch pipeline with a project that I want to build only if there are changes in a specific directory.
I know that the Polling ignores commits in certain paths option can do exactly that but I can't find this option in the multibranch configuration.
Is this even possible for multibranch pipeline?
Theoretically, you can call the GitSCM class with an includedRegions path restriction in the checkout step (e.g. see here for the syntax).
However, this is not working with pipelines, as I just checked it last week. So unfortunately, Jenkins is really not well-suited for monorepos.

Resources