Can I specific a single Jenkinsfile for multibranch pipeline in Jenkins? - jenkins

By default, Jenkins multibranch pipeline discovers branches of my GIT repository. It can execute the related Jenkinsfile for the target branch. However, this design force me to create one version of Jenkinsfile for one branch and this cause Jenkinsfile maintenance overhead.
If I can ensure I will have only 1 version of Jenkinsfile, is it possible for multibranch pipeline to point to such Jenkinsfile instead of referencing Jenkinsfile of the target branch?

Related

Jenkins multi-branch pipeline - scm object of the Jenkinsfile?

In Jenkins pipeline projects, I can reference the repo of the Jenkinsfile using the scm variable, e.g. checkout scm clones the exact repo at the commit that Jenkins uses for the current build.
Now, I am using a multi-branch project that gets the branches (and the corresponding source) from one repo, but the Jenkinsfile from another one. I.e. "Pipeline" is configured as "Pipeline script from SCM".
In that scenario, the scm variable during the build refers to the branch from the multi-branch config, not to the Jenkinsfile. How do I get the SCM object of the Jenkinsfile's repo?

Jenkins multibranch with Jenkinsfile in different repo

If use a multibranch pipeline in Jenkins, I want to have a build for every specific branch that is made inside my code repo. This works like a charm. But I don't want to provide a Jenkinsfile inside my code repo. Instead I want to define a different CI repo which is providing my CI pipeline scripts.
The problem is that the usual config is not containing the scm option like in the normal config.
Normal pipeline config:
Multibranch pipeline config:
Can somebody tell me how to separate the Jenkinsfile from my source code using a multibranch pipeline?
Just in case someone stunmles over the same problem,
there is a Jenkins plug-in which brings remote Jenkinsfiles for mutlibranch pipleines: https://plugins.jenkins.io/remote-file/

Jenkins BlueOcean only to build using a single branch for build?

When I build a multibranch pipeline job using BlueOcean it looks into my repository and reads all of my Jenkinsfile for each branch. to initiates multiple build, but I only want to be able to build a job based on a certain branch. Is there a way to only build blueocean?
Thanks
I sounds like your job is a Multibranch Pipeline.
If you create a job that is just a Pipeline (rather than Multibranch Pipeline), you can specify a single specific branch to build.

How to fool Jenkins into thinking all branches already ran in multibranch pipeline?

I'm using multibranch pipelines to build a project in a git repo with many (mostly dormant) branches. The various Jenkinsfiles are all stored in the git repo.
The multibranch pipeline jobs are all defined using the job-dsl plugin. I have a problem when I run the job-dsl scripts; even when a job-dsl job definition wasn't updated (and the multibranch pipeline job wasn't updated), Jenkins queues all branches for build. Due to the large number of branches (and possibly some jobs/branches that run on the master itself), this eventually causes the master to crash.
How can I mark all branches as "already built" and avoid this massive redundant build event when I run my job-dsl generation job?
Jenkins 2.89.4
job-dsl 1.68
Specifying an id for the SCM source solved that problem a while ago for me:
multibranchPipelineJob {
branchSources {
github {
id('some-id')
// ..
}
}
}

Jenkins Multibranch pipeline fails if branch does not have jenkinsfile

I have a legacy build system on which I want to incrementally add multibranch pipeline support to branches so all branches will build and test for Continuous Integration. However ... old branches do not have a jenkinsfile present and a multibrach pipeline build fails with FileNotFoundException.
The pipeline works just fine on my new branches. It finds the jenkinsfile and runs the build fine. Can I have the pipeline filter out or ignore older branches that do not have a jenkinsfile?

Resources