Skip to main content
40 votes
Accepted

How to properly achieve dynamic parallel action with a declarative pipeline?

Managed to solve it with the following code: pipeline { agent { label "master"} stages { stage('1') { steps { script { def tests = [:] ...
thclpr's user avatar
  • 841
22 votes
Accepted

Running a background process in Pipeline job

Any one facing the same problem and using pipeline project, set JENKINS_NODE_COOKIE instead of BUILD_ID. Dont waste your time setting HUDSON_COOKIE, HUDSON_SERVER_COOKIE, JENKINS_COOKIE or ...
Dharanidhar's user avatar
15 votes

How to properly achieve dynamic parallel action with a declarative pipeline?

This also works, if you want to stay within the Declarative Pipeline space // declare our vars outside the pipeline def tests = [:] def files pipeline { agent any stages { stage('1') ...
primetheus's user avatar
15 votes

Triggering specific pipeline builds for monorepos in Jenkins

You can use the "when" block combined with the built in "changeset" condition to conditionally run only certain stages of your monorepo's pipeline. From the when.changeset documentation: changeset- ...
mancini0's user avatar
  • 251
11 votes
Accepted

How to build a complex parallel Jenkins pipeline?

Based on the comments to my question, and some basic testing the following seems to work: Use nested parallel statements. (Thanks @lawnmowerlatte) Although today (May 15th 2017) Jenkins Blue ocean ...
Bert Goethals's user avatar
9 votes

How to retrigger a Jenkins build after failure using declarative syntax?

The other answer is incorrect. There is indeed a builtin to retry arbitrary sections of your job called retry. If you want to retry the whole job three times, you can wrap your entire job in a retry ...
jayhendren's user avatar
  • 2,992
8 votes
Accepted

How to make Jenkinsfile credential visible to many stages

The credentials will only be visible within the block passed to withCredentials, not outside of that. So, no, your credentials will not be visible to other stages. To make your credentials visible ...
jayhendren's user avatar
  • 2,992
8 votes
Accepted

One Jenkinsfile or multiple?

It really comes down to personal preference. One additional tool you might not be aware of are shared libraries for Pipeline. These allow you to quickly write custom Pipeline steps or factor out ...
jayhendren's user avatar
  • 2,992
7 votes

How to properly achieve dynamic parallel action with a declarative pipeline?

Be aware, that dynamic build steps could cause some problems in some build steps, e.g. when you call an other job: pipeline { stages { stage('Test') { steps { ...
Christian Gripp's user avatar
7 votes
Accepted

How not to break Jenkins Pipeline when adding new parameters (declarative pipeline)

Here is a solution which seems almost like a workaround that I have found which works for declarative pipelines. First, we need to add some code at the start of our file before we enter into the ...
Inbar Rose's user avatar
7 votes
Accepted

How to have jenkins add a review to a pull request

I guess the simplest and direct solution would be to use GitHub API: https://docs.github.com/en/rest/reference/pulls#create-a-review-for-a-pull-request But for the requirement you have, PR checks is ...
froblesmartin's user avatar
5 votes

Jenkins libraries configuration in Jenkinsfile

You should look at Global Shared Libraries, which will allow you to reuse logic across different Jenkinsfiles. Rather than depending on the environment, it's probably safer to explicitly pass ...
Michael Pereira's user avatar
5 votes

How to build a complex parallel Jenkins pipeline?

I had a similar situation in which I wanted to nest other parallel jobs threads inside another parallel one. This code worked for me: def performDeploymentStages(String node, String app) { stage("...
biniosuaf's user avatar
5 votes
Accepted

Triggering specific pipeline builds for monorepos in Jenkins

Get a list of changed files and use that to determine which tests to run. Load external Groovy scripts at run time in order to run your deploys.
jayhendren's user avatar
  • 2,992
5 votes

One Jenkinsfile or multiple?

Having been down a similar road, here are my suggestions: Break your tasks apart by function; build is different to deploy, which is different to release. You can get more granular, but let's stick ...
Denham Coote's user avatar
5 votes
Accepted

Using a conditional environment{ } directive in Jenkinsfiles

I often have an extra Prepare stage to calculate these logics: stage('Prepare') { steps { script { switch(branch_name) { case 'dev' : env.VAR_1 = x; ...
minhluantran017's user avatar
4 votes

Does TFS Build have something like a Jenkinsfile?

Visual Studio Team Services has a YAML Build feature in public preview that allows you to store your build definitions as source controlled files.
Daniel Mann's user avatar
4 votes
Accepted

Does TFS Build have something like a Jenkinsfile?

The strict answer is no, in that there is no direct equivalent to a Jenkinsfile. However, there are Build Process Templates and you can use the Psake Build Automation tool in combination with ...
Richard Slater's user avatar
4 votes

Accessing the committer's name as a Jenkinsfile environment variable

I'm not entirely sure what you're trying to ask in your question, so I'm answering the question I believe you're trying to ask. A build does not necessarily have a single commit author. It has a ...
jayhendren's user avatar
  • 2,992
4 votes

Why does the Jenkins bitbucket-build-status-notifier-plugin post the status to the shared pipeline library repository?

This is a known bug. See JENKINS-42878 and JENKINS-41996. This bug has been resolved upstream, which means you should be able to fix the bug by upgrading the plugin to the latest version.
jayhendren's user avatar
  • 2,992
4 votes
Accepted

How do I trigger scripts on a merge or when a branch is deleted?

"This is great, but I want to run a command/script when a branch is removed, how can I have jenkins run a command when a branch is removed?" You will need to use a webhook for this, I use the ...
Kyle Steenkamp's user avatar
4 votes

How to check return status of parallel branches in jenkins pipeline

I tried storing the slave job part status in a file and stashing it on node and then unstashing it back on master. It works but I am looking for a cleaner way. Following is the current approach i am ...
Anirudh Singh's user avatar
4 votes

Jenkins Pipeline Kubernetes Agent shared Volumes

To solve this, you need to include the volume mounts in the containers described here: Sample Jenkinsfile: pipeline { agent { kubernetes { label 'test-pod' defaultContainer 'jnlp'...
Inbar Rose's user avatar
4 votes

How to make Jenkinsfile credential visible to many stages

I set credential globally in declarative pipeline like this and then my Jenkins could talk with Google Dataflow in all stages. For example, I used a secret file (google service account). pipeline { ...
Qin Ma's user avatar
  • 41
4 votes

Jenkins Pipeline project can't when on branch

This is the way to go: stage('Deploy'){ when { expression {env.GIT_BRANCH == 'origin/master'} } steps { .... } } Take care, this is only working with the declarative syntax. The ...
alex's user avatar
  • 51
4 votes

Is there a way to use a Jenkinsfile from a git-submodule in a multibranch pipeline?

I agree with Omri that you are heading the wrong way. I would recommend using a shared library which implements the pipeline. You would then have a simple Jenkins file which looks all the same. See ...
papanito's user avatar
  • 283
4 votes
Accepted

How to mark a step as failed or unstable on timeout, instead of aborting build?

I've done something similar to this in the past: stage('Step Tests') { steps { dir('test') { script { try { timeout(time: 5, unit: 'MINUTES', activity: true) { ...
jayhendren's user avatar
  • 2,992
4 votes
Accepted

Prevent ${PIPELINESTATUS[0]} from being evaluated in Jenkinsfile

There seems to be some syntax issues and also I would suggest to use bash instead if using sh shell. Try the below code and see if this works properly. (EDIT - Put shebang on first line to accept as ...
Samit's user avatar
  • 1,021
3 votes

Is there a way to run the Jenkinsfile from command line?

I've done this before. Essentially you can use the Jenkins CLI to import/export jobs, which will allow you to create and/or update a job with the definition you want to run. Be it JenkinsFile or some ...
Jiri Klouda's user avatar
  • 5,837
3 votes

How to check return status of parallel branches in jenkins pipeline

You may want to try the Join plugin. Some more details about this plugin (from the linked page): This plugin allows a job to be run after all the immediate downstream jobs have completed. In this ...
Pierre.Vriens's user avatar
  • 7,215

Only top scored, non community-wiki answers of a minimum length are eligible