When I build a job using Multibranch pipeline, Jenkins is not creating workspace repository which is more than 32 character. It trims the character from starting of the job name.
Job name: multi-branch-jenkins-pipeline
Branch: Dev
what i want jenkins to create workspace: multi-branch-jenkins-pipeline_dev
what Jenkins create: iple-branch-jenkins-pipeline_dev
What i tried Djenkins.branch.WorkspaceLocatorImpl.PATH_MAX=40 Didn't Work
Related
I have a multi-branch pipeline job which does a build/test on a specific branch.
I would like to create a new Jenkins job, which 'loads' a new branch into the multi-branch pipeline, runs the pipeline 3 times with 3 different options then cleans up and removes the branch.
Here is my use case example:
Set up - add branch release-19.0.4 branch to multi-branch pipeline
Run multi-branch pipeline on branch release-19.0.4 with parameter support-version=19.0.3
Run multi-branch pipeline on branch release-19.0.4 with parameter support-version=19.0.0
Run multi-branch pipeline on branch release-19.0.4 with parameter support-version=18.0.0
Write report: support-version=19.0.3 - ok, support-version=19.0.0 - ok, support-version=18.0.0 - failed
Tear down - remove release-19.0.4 branch from mule-branch pipeline job.
I can use build pipeline task to build another job with different options and read the success or failure of that job in order to create my report. However I'm stuck on how to do steps 1) and 6) from within a Jenkinsfile.
I've tried to read through the Jenkins pipeline API's but nothing seems to fit. Any ideas how to do this via automation?
In a Jenkinsfile, to start a parameterized pipeline job from another job, I have this code snippet:
build job: 'build-sharpen-branch', parameters: [
[$class: 'StringParameterValue', name: 'BRANCHNAME', value: mergeBranchname]
]
This already works as expected, and it will start a job at URL https://$JENKINS_URL/job/build-sharpen-branch/.
Now I want to start a job, that is one branch of a multibranch project inside a Bitbucket folder. The URL of the job is https://$JENKINS_URL/job/iText%207%20.NET/job/sharpen/job/feature%2FQA-10738/.
iText%207%20.NET is the name of the Bitbucket project.
sharpen is the name of the Multibranch job.
feature%2FQA-10738 is the name of the branch, urlencoded.
I read the following questions about starting a multibranch job NOT inside a folder:
Trigger Multibranch Job from another
Triggering a multibranch pipeline job from an other multibranch pipeline
How to trigger Multibranch Pipeline Jenkins Job within regular pipeline job?
From the answers there, I gather that the syntax is $JOB/$BRANCH (where $BRANCH is URL-encoded to rename branches like feature/foo to feature%2Ffoo).
From Jenkins pipeline with folder plugin. How to build a job located different folder I gather that the syntax for a job inside a folder is $FOLDER/$JOB.
Combining the two, I conclude that the syntax for folder+job+branch is most likely $FOLDER/$JOB/$BRANCH.
So I tried with this code:
build job: "iText%207%20.NET/sharpen/${java.net.URLEncoder.encode branchName, 'UTF-8'}"
with
folder = iText%207%20.NET
job = sharpen
branch = ${java.net.URLEncoder.encode branchName, 'UTF-8'} (URLEncoder to change / in the branch name to %2F)
To my surprise, when I ran this, I got an error:
ERROR: No item named iText%207%20.NET/sharpen/feature%2FQA-10738 found
As already stated above, a job exists on URL https://$JENKINS_URL/job/iText%207%20.NET/job/sharpen/job/feature%2FQA-10738/.
What is the correct syntax for a multibranch job inside a Bitbucket folder?
The problem was with the folder name iText%207%20.NET, which is an urlencoded version of iText 7 .NET. Apparently Jenkins can't handle urlencoded spaces in folder names.
I renamed the folder to itext_7_dotnet and then used
build job: "itext_7_dotnet/sharpen/${java.net.URLEncoder.encode branchName, 'UTF-8'}"
This works.
Moral of the story: never use spaces in your folder names!
For us, this works:
build job: "${folder}/${repo}/${branch.replace('/','%2F')}", wait: false, propagate: false
You can also trigger build by using curl, with crumbs and all that.
I have a Jenkinsfile located in [my svn branch]\build folder, and it checks out code to the slave node and builds.
My multi branch project finds the branch correctly, but it checks out the entire svn branch on the master just to read the jenkinsfile instead of checking out just the jenkinsfile itself of just [my svn branch]\build folder.
This is a major problem because of storage and performance, are there any solutions for that?
In your multibranch pipeline config in 'include' field type: branches/*/build (i assume that you have all svn branches in folder 'branches', and url to your build folder is something like: svn_url/branches/my_new_branch/build)
Then it will scan only build folder in each branch.
Warning - after changing that config property your multibranch pipeline will only diacover 'build', if you want to index other build folders, you can list them in that property, i.e.:
Include: trunk/build, trunk/other_build, branches/*/build, branches/*/other_build
But more clean approach is to get only one build per multibranch pipeline
I have a scenario where but I have 2 projects (A and B), both are configured in Jenkins with multibranch pipeline jobs, problem is that Project B depends on Project A.
So I find that some times when I check in code in Project A, I also need to build ProjectB once A was built. Now before I started investigating pipeline builds, I'd have a job per branch and then trigger in Jenkins the appropriate job for Project B for the appropriate branch.
What I'd like to set up in a Jenkinsfile so that when ProjectA/develop executes it then triggers the multibranch pipeline job for ProjectB and the same branch.
I have:
stage ('Trigger Tenant Builds') {
build job: "ProjectB/${branch}", wait: false
}
But my ProjectA pipeline fails with:
ERROR: No parameterized job named ProjectB/develop found
Any ideas?
I've resolved this now. What I am doing is defining an upstream trigger in project B's Jenkinsfile:
pipelineTriggers([
upstream(
threshold: hudson.model.Result.SUCCESS,
upstreamProjects: "/ProjectA/" + env.BRANCH_NAME.replaceAll("/", "%2F")
)
])
I am trying to create a multi-configuration project that tests a bunch of builds that defines a compatibility matrix (for example by browser and os). I would like to define the steps for a single combination via Jenkinsfile.
How can I achieve this? I can create a pipeline parameterized build which depends on JenkinsFile but I can't figure out how to connect it to the multi-configuration build.
It does not appear to be possible to have a Jenkinsfile as a buildstep in a multi-configuration project. A Jenkinsfile is used in a Pipeline job which is a jobtype aswell and Jenkins does not support (easy) conversion between jobtypes. In addition to that, a buildstep implies that it is run on a particular node in an executor slot. A Jenkinsfile however is evaluated on the master and itself defines buildsteps (with their node labels) which would inherently clash if it was run in a buildstep itself.
It is possible to trigger a pipeline through a multi-configuration job and supply it with the parameters from the multi-configuration job. (I also used the parameterized trigger plugin to do this)
My pipeline job has two text parameters, label and version with a example Jenkinsfile that looks like this:
node(this.label){
println this.version
}
My multi-configuration job has the following configuration:
A custom axis version with values alpha beta gamma and a slave axis label with a selected node
The buildstep "Trigger/call builds on other projects" to trigger my pipeline job with predefined parameters version=${version} and label=${label}
This setup leads to the pipeline job being called 3 times (as I have only one node selected), each time with a different version and running on my specified label. Here is one of the logs:
[Pipeline] node
Running on master in /var/lib/jenkins/jobs/pipelinejob/workspace
[Pipeline] {
[Pipeline] echo
gamma
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
This solution works if you only want to pass text based parameters or label names. It will be considerably trickier to use if you want to do something like "build with different jdks". I hope it is still helpful though.