39 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 = [:] ...
user avatar
  • 801
20 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 ...
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- ...
user avatar
  • 251
12 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') ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 2,733
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 ...
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 ...
user avatar
6 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 ...
user avatar
  • 2,733
6 votes
Accepted

How to make Jenkinsfile credential visible to many stages

No, the credentials will only be visible within the block passed to withCredentials, not outside of that. There is no way to make the credentials globally available without switching to Scripted ...
user avatar
  • 2,733
5 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 { ...
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.
user avatar
  • 2,733
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("...
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 ...
user avatar
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 ...
user avatar
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.
user avatar
  • 2,733
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 ...
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 ...
user avatar
  • 2,733
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.
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 ...
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'...
user avatar
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 ...
user avatar
  • 51
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) { ...
user avatar
  • 2,733
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 ...
user avatar
  • 5,607
3 votes

Using Artifactory plugin in Jenkins declarative pipeline

You can have conditionals in your declarative pipeline by using the when-block inside a stage. There is a plugin called "environment injector" which lets you set variables outside of the pipeline-...
user avatar
3 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 ...
user avatar
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 ...
user avatar
  • 6,848
3 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 { ...
user avatar
  • 31
3 votes
Accepted

Jenkins parameters default to env variable?

You need to use double quotes instead of single quotes. Single-quoted strings don't perform string interpolation. For instance: parameters { string( name: 'DEPLOY_BUILD_NUMBER', ...
user avatar
  • 2,733
3 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 ...
user avatar
  • 271

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