Proper configuring of Multibranch Pipeline in Jenkins - jenkins

How do I properly configure a Multibranch Pipeline in Jenkins when Git is selected as branch source? I get a "Does not meet criteria" for every branch that is checked in the branch indexing log.

This Multibranch Pipeline job will create a pipeline job if your Git branch contains a Jenkinsfile.
This Jenkinsfile describe how to build the current branch (Jenkins Groovy DSL).
If your branch doesn't contain a Jenkinsfile, then you will get this "does not meet criteria" message.
More information about the Multibranch pipeline here.

Also make sure your Jenkinsfile does not have a .groovy extension

At least on Windows the casing of the Jenkinsfile is important. It has to be with an uppercase "J" and the rest lowercase.
Jenkinsfile

It appears to check the script type. The first line of "Jenkinsfile" had to be:
"#!groovy"

As Bruno Lavit points out the criteria is pretty simple.
I believe you may have an issue with your current branch.
In a clean environment, try to checkout the branch and verify that the Jenkinsfile is indeed included and that is it a valid text file.
I had a similar issue in the past where my push did not finished correctly.

I think that your jenkins plugin (Git plugin and Git Client plugin) is old.
Try to update the plugins.

I run into this when I added Jenkinsfile after I had created the Multibranch Pipeline project. The solution was to delete the project and create again :)
Still, for some Jenkins-only-know reason, it doesn't run the build on my master branch now.

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 edit / define Jenkinsfile text within Jenkins job?

Sometimes it is not possible (yet) to put Jenkinsfile into git repository.
I think it was possible to edit/define Jenkinsfile content just within job,
but with latest Jenkins, I cannot find such support.
Now I see only filename configuration.
OK, just be sure to select usual Pipeline project and not Multibranch pipeline

Multibranch pipeline with jenkinsfile in svn:external

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"

Update manually commit and branch attributes from jenkins pipeline blueocean

We are using jenkins for manual triggered jobs to deploy some code.
Jenkinsfile describing our pipeline is located in a jenkinsfile dedicated repo (not in deployed code repo).
We are using declarative pipeline syntax and shared libraries in our jenkinsfiles.
In BlueOcean interface there are 2 interesting attributes (branch and commit) automatically filled when using plugins to trigger pipelines (like github organization).
I'm searching a way to set/update these 2 attributes manually from within the pipeline code for our manual pipelines.
Job description and name can be easily updated using something like :
stage('Set pipeline description'){
steps {
script {
currentBuild.description = "Deploying branch ${branch} on ${targetEnv}"
}
}
}
But I didn't find anywhere how to update branch or commit values.
Did anybody try this ?
This issue is reported as bug (see link).
"We are using GitLab web hooks to trigger Jenkins Pipeline project builds on new commit push to GitLab. Build is triggered, CI commit status report is being sent back to gitlab, but can't see branch and commit field in Header-details element."
Please vote on this issue on Jenkins CI website if you want for the issue to be resolved sooner.

Jenkinsfile in groovy read the git tag

I would like to prepare 2 jobs in the same jenkins server that will read from a specific branch. I have to use the git tag for one of the jobs as to separate them somehow.
Please, could you paste some code containing the job trigger in jenkins using a git tag ?
Ok based on your comment:
jenkins changed lately and some of the old UI functions need to be placed into a groovy pipeline
I think this is a duplicate of this question: I pull the branch with tag in the groovy
The answer is perfect for what you are asking.
hope this helps.

Resources