Questions tagged [jenkins-workflow]

Use the "jenkins-pipeline" tag instead for problems using the "Pipeline" (formerly known as Workflow) plugin suite for Jenkins continuous integration.

The Jenkins Pipeline feature, first released in November 2014 (originally called “Workflow”), allows you to define complex orchestrations of build processes in a concise Groovy script. It is not a build tool itself, but a way of letting builds interact with Jenkins-specific features such as slaves, test reports, and so on.

Questions using this tag should be related to this plugin, typically installed as Pipeline and dependencies, and to projects created using the Pipeline option in the New Item page. Tagged questions might cover best usage and idioms, or apparent bugs that you are not sufficiently confident about to immediately file in JIRA, or status of integrations with other plugins, etc.

Not to be confused with the older Build Flow DSL plugin, which Pipeline took as inspiration; nor with the Job DSL plugin, which covers an orthogonal problem (creating multiple similar jobs automatically); nor to the assemblies of “freestyle” projects using various other plugins which Pipeline is intended to supersede in part or in whole (Parameterized Trigger, Copy Artifact, Join, Promoted Builds, Build Pipeline, EnvInject, etc.).

This plugin was formerly known as Workflow plugin. It was renamed to Pipeline in January 2016.

Links:

376 questions
302
votes
16 answers

How can I test a change made to Jenkinsfile locally?

When writing jenkins pipelines it seems to be very inconvenient to commit each new change in order to see if it works. Is there a way to execute these locally without committing the code?
sorin
  • 161,544
  • 178
  • 535
  • 806
217
votes
5 answers

How can I trigger another job from a jenkins pipeline (jenkinsfile) with GitHub Org Plugin?

How can I trigger build of another job from inside the Jenkinsfile? I assume that this job is another repository under the same github organization, one that already has its own Jenkins file. I also want to do this only if the branch name is…
sorin
  • 161,544
  • 178
  • 535
  • 806
114
votes
7 answers

Is it possible to capture the stdout from the sh DSL command in the pipeline

For example: var output=sh "echo foo"; echo "output=$output"; I will get: output=0 So, apparently I get the exit code rather than the stdout. Is it possible to capture the stdout into a pipeline variable, such that I could get: output=foo as my…
Jesse S
  • 1,595
  • 2
  • 11
  • 10
94
votes
4 answers

Get absolute path to workspace directory in Jenkins Pipeline plugin

I'm currently doing some evaluation on the Jenkins Pipeline plugin (formerly know as Workflow plugin). Reading the documentation I found out that I currently cannot retriev the workspace path using env.WORKSPACE: The following variables are…
Joerg S
  • 4,730
  • 3
  • 24
  • 43
83
votes
9 answers

Show a Jenkins pipeline stage as failed without failing the whole job

Here's the code I'm playing with node { stage 'build' echo 'build' stage 'tests' echo 'tests' stage 'end-to-end-tests' def e2e = build job:'end-to-end-tests', propagate: false result = e2e.result if…
techgnosis
  • 1,879
  • 2
  • 17
  • 19
78
votes
3 answers

How do I implement a retry option for failed stages in Jenkins pipelines?

I have a Jenkinsfile with multiple stages and one of them is in fact another job (the deploy one) which can fail in some cases. I know that I can made prompts using Jenkinsfile but I don't really know how to implement a retry mechanism for this…
sorin
  • 161,544
  • 178
  • 535
  • 806
61
votes
4 answers

Jenkins pipeline plugin: set the build description

I'm trying to replace our current build pipeline, currently hacked together using old-school Jenkins jobs, with a new job that uses the Jenkins pipeline plugin, and loads a Jenkinsfile from the project repository. One thing that the legacy job did…
jjst
  • 2,631
  • 2
  • 22
  • 34
61
votes
2 answers

How to set variables in a multi-line shell script within Jenkins Groovy?

Suppose I have a Groovy script in Jenkins that contains a multi-line shell script. How can I set and use a variable within that script? The normal way produces an error: sh """ foo='bar' echo $foo """ Caught:…
Fo.
  • 3,752
  • 7
  • 28
  • 44
59
votes
4 answers

How to implement Post-Build stage using Jenkins Pipeline plug-in?

After reading Jenkins tutorial explaining Pipeline plug-in, it seems that plug-in should make it possible to implement Post-Build steps. However documentation is rather limited in regard to specific instructions. For example I wonder how to…
luka5z
  • 7,525
  • 6
  • 29
  • 52
56
votes
3 answers

How do I use Jenkins Pipeline properties step?

I am studying capabilities of Jenkins Pipeline:Multibranch. It is said that a recently introduced properties step might be useful there, but I can't catch how it works and what is its purpose. Its hint message doesn't seem to be very clear: Updates…
izzekil
  • 5,781
  • 2
  • 36
  • 38
48
votes
4 answers

How can I use the Jenkins Copy Artifacts Plugin from within the pipelines (jenkinsfile)?

I am trying to find an example of using the Jenkins Copy Artifacts Plugin from within Jenkins pipelines (workflows). Can anyone point to a sample Groovy code that is using it?
sorin
  • 161,544
  • 178
  • 535
  • 806
44
votes
6 answers

How can I reference the Jenkinsfile directory, with Pipeline?

I have a groovy file, I want to run from the Jenkinsfile. ie. load script.groovy However, I am not sure how I can reference this file if it is stored in the same directory as the Jenkinsfile. I am loading the Jenkinsfile from git. I noticed it…
CodyK
  • 3,426
  • 4
  • 36
  • 52
44
votes
4 answers

Access Stage name during the build in Jenkins pipeline

Let's say we have the following Jenkinsfile: stage name: "Cool stage" sh 'whoami' stage name: "Better stage" def current_stage = getCurrentStageName() echo "CONGRATULATIONS, you are on stage: $current_stage" The question is how to…
Aleks
  • 1,301
  • 2
  • 12
  • 9
43
votes
6 answers

How to call REST from jenkins workflow

I wonder how to call REST API from a (groovy) Jenkins workflow script. I can execute "sh 'curl -X POST ...'" - it works, but building the request as a curl command is cumbersome and processing the response gets complicated. I'd prefer a native…
Assen Kolov
  • 4,143
  • 2
  • 22
  • 32
36
votes
7 answers

Jenkins Build Pipeline - Restart At Stage

I have the following build pipeline set up as a job: Stage 1 - verify all dependencies exist Stage 2 - build the new jar Stage 3 - Run integration tests Stage 4 - Deploy to staging environment (manual step) Stage 5 - Deploy to production environment…
threejeez
  • 2,314
  • 6
  • 30
  • 51
1
2 3
25 26