Skip to main content

Questions tagged [jenkins-pipeline]

Questions about the Jenkins “Pipeline” plugin suite (formerly “Workflow”). Not about pipelines in Jenkins in general (e.g. using downstream jobs).

Filter by
Sorted by
Tagged with
961 votes
17 answers
723k views

Error "The input device is not a TTY"

I am running the following command from my Jenkinsfile. However, I get the error "The input device is not a TTY". docker run -v $PWD:/foobar -it cloudfoundry/cflinuxfs2 /foobar/script.sh Is there a ...
Anthony's user avatar
  • 35.3k
565 votes
44 answers
739k views

Docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

I am new to docker. I just tried to use docker in my local machine(Ubuntu 16.04) with Jenkins. I configured a new job with below pipeline script. node { stage('Build') { docker.image('maven:...
Ponsuyambu's user avatar
  • 8,466
375 votes
10 answers
669k views

How do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?

I have something like this on a Jenkinsfile (Groovy) and I want to record the stdout and the exit code in a variable in order to use the information later. sh "ls -l" How can I do this, especially ...
sorin's user avatar
  • 167k
314 votes
16 answers
229k views

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's user avatar
  • 167k
250 votes
4 answers
204k views

Jenkins: Can comments be added to a Jenkinsfile?

Are comments possible in a Jenkinsfile? If so, what's the syntax? I am using the declarative pipeline syntax. I want to comment out the "post" section below until my SMTP server is working. ...
danday74's user avatar
  • 55.3k
226 votes
5 answers
469k views

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 ...
sorin's user avatar
  • 167k
200 votes
1 answer
157k views

Jenkins pipeline: agent vs node?

What is the difference between an agent and a node in a jenkins pipeline? I've found those definitions: Node: A Pipeline performs most of the work in the context of one or more declared node steps. ...
Matthias M's user avatar
  • 14.2k
189 votes
15 answers
347k views

Jenkins Pipeline Wipe Out Workspace

We are running Jenkins 2.x and love the new Pipeline plugin. However, with so many branches in a repository, disk space fills up quickly. Is there any plugin that's compatible with Pipeline that I ...
qmo's user avatar
  • 3,148
162 votes
21 answers
279k views

How to list all `env` properties within jenkins pipeline job?

Given a jenkins build pipeline, jenkins injects a variable env into the node{}. Variable env holds environment variables and values. I want to print all env properties within the jenkins pipeline. ...
JamesThomasMoon's user avatar
161 votes
8 answers
375k views

Jenkins CI Pipeline Scripts not permitted to use method groovy.lang.GroovyObject

I am Using Jenkins 2 for compiling Java Projects, I want to read the version from a pom.xml, I was following this example: https://github.com/jenkinsci/pipeline-plugin/blob/master/TUTORIAL.md The ...
Daniel Hernández's user avatar
161 votes
5 answers
325k views

Conditional step/stage in Jenkins pipeline

How do you run a build step/stage only if building a specific branch? For example, run a deployment step only if the branch is called deployment, leaving everything else the same.
Devonte's user avatar
  • 3,405
157 votes
8 answers
473k views

Checkout Jenkins Pipeline Git SCM with credentials?

I was following this tutorial: node { git url: 'https://github.com/joe_user/simple-maven-project-with-tests.git' ... } However it doesn't tell how to add credentials. Jenkins does have specific "...
Render's user avatar
  • 2,319
149 votes
3 answers
276k views

Jenkins pipeline how to change to another folder

Currently i am using Jenkins pipeline script. For running one command, I need to access a folder outside its workspace directory. I tried sh "cd $workspace/", but it returned current workspace ...
wanderors's user avatar
  • 2,222
144 votes
9 answers
308k views

Cannot define variable in pipeline stage

I'm trying to create a declarative Jenkins pipeline script but having issues with simple variable declaration. Here is my script: pipeline { agent none stages { stage("first") { ...
Malcolm Crum's user avatar
  • 4,731
135 votes
8 answers
200k views

How do I pass variables between stages in a declarative Jenkins pipeline?

How do I pass variables between stages in a declarative pipeline? In a scripted pipeline, I gather the procedure is to write to a temporary file, then read the file into a variable. How do I do this ...
John's user avatar
  • 11.6k
133 votes
5 answers
193k views

How to add a timeout step to Jenkins Pipeline

When you are using a free style project you can set that after 20 minutes the build is aborted if not concluded. How is this possible with a Jenkins Multi Branch Pipeline Project?
Devonte's user avatar
  • 3,405
125 votes
2 answers
214k views

Check if a file exists in jenkins pipeline

I am trying to run a block if a directory exists in my jenkins workspace and the pipeline step "fileExists: Verify file exists" in workspace doesn't seem to work correctly. I'm using Jenkins v 1.642 ...
Balualways's user avatar
  • 4,400
122 votes
5 answers
101k views

Configuring Groovy SDK within IntelliJ IDEA

I am running IntelliJ IDEA 2017.2.3. I installed Groovy 2.4.12 via Homebrew (OS X). When I open a Groovy source file (or a Jenkinsfile), I get the following: Groovy SDK is not configured for module ...
Carl Patenaude Poulin's user avatar
119 votes
13 answers
123k views

Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap

Solved: Thanks to below answer from S.Richmond. I needed to unset all stored maps of the groovy.json.internal.LazyMap type which meant nullifying the variables envServers and object after use. ...
Sunvic's user avatar
  • 1,592
119 votes
7 answers
161k views

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 ...
Jesse S's user avatar
  • 1,658
119 votes
8 answers
81k views

Jenkins scripted pipeline or declarative pipeline

I'm trying to convert my old style project base workflow to a pipeline based on Jenkins. While going through docs I found there are two different syntaxes named scripted and declarative. Such as the ...
Nayana Adassuriya's user avatar
118 votes
4 answers
195k views

Failing a build in Jenkinsfile

Under certain conditions I want to fail the build. How do I do that? I tried: throw RuntimeException("Build failed for some specific reason!") This does in fact fail the build. However, the log ...
oillio's user avatar
  • 4,858
117 votes
6 answers
93k views

"Build Periodically" with a Multi-branch Pipeline in Jenkins

I'm running Jenkins 2 with the Pipeline plugin. I have setup a Multi-branch Pipeline project where each branch (master, develop, etc.) has a Jenkinsfile in the root. Setting this up was simple. ...
geowa4's user avatar
  • 41.3k
116 votes
11 answers
109k views

How to write Pipeline to discard old builds?

The groovy syntax generator is NOT working for sample step properties: Set Job Properties. I've selected Discard old builds and then entered 10 in the Max # of builds to keep field and then Generate ...
tarabyte's user avatar
  • 18.7k
113 votes
8 answers
164k views

Continue Jenkins pipeline past failed stage

I have a series of stages that perform quick checks. I want to perform them all, even if there are failures. For example: stage('one') { node { sh 'exit 0' } } stage('two') { ...
John McGehee's user avatar
  • 9,871
102 votes
5 answers
150k views

Using a Jenkins pipeline to checkout multiple git repos into same job

I'm using the Jenkins Multiple SCM plugin to check out three git repositories into three sub directories in my Jenkins job. I then execute one set of commands to build a single set of artifacts with ...
Gordon's user avatar
  • 3,092
100 votes
10 answers
305k views

How to access parameters in a Parameterized Build?

How do you access parameters set in the "This build is parameterized" section of a "Workflow" Jenkins job? TEST CASE Create a WORKFLOW job. Enable "This build is parameterized". Add a STRING ...
Vizionz's user avatar
  • 1,167
99 votes
4 answers
290k views

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 ...
Joerg S's user avatar
  • 5,019
97 votes
4 answers
132k views

How to create methods in Jenkins Declarative pipeline?

In Jenkins scripted pipeline we are able to create methods and can call them. Is it possible also in the Jenkins declarative pipeline? And how?
vinesh vini's user avatar
  • 1,071
92 votes
12 answers
127k views

How do I prevent two pipeline jenkins jobs of the same type to run in parallel on the same node?

I do not want to allow two jobs of the same type (same repository) to run in parallel on the same node. How can I do this using groovy inside Jenkinsfile ?
sorin's user avatar
  • 167k
92 votes
6 answers
158k views

What is the branch name variable for Jenkins multibranch pipelines?

I need to know which branch is being built in my Jenkins multibranch pipeline in order for it to run steps correctly. We are using a gitflow pattern with dev, release, and master branches that all are ...
Christian Rigdon's user avatar
91 votes
13 answers
257k views

Get git branch name in Jenkins Pipeline/Jenkinsfile

I've create a jenkins pipeline and it is pulling the pipeline script from scm. I set the branch specifier to 'all', so it builds on any change to any branch. How do I access the branch name causing ...
Alex Yurkowski's user avatar
91 votes
6 answers
122k views

How to invoke a jenkins pipeline A in another jenkins pipeline B

I have two Jenkins pipelines, let's say pipeline-A and pipeline-B. I want to invoke pipeline-A in pipeline-B. How can I do this? (pipeline-A is a subset of pipeline-B. Pipeline-A is responsible for ...
Yash's user avatar
  • 3,054
88 votes
6 answers
171k views

How do you load a groovy file and execute it

I have a jenkinsfile dropped into the root of my project and would like to pull in a groovy file for my pipeline and execute it. The only way that I've been able to get this to work is to create a ...
user301693's user avatar
  • 2,467
88 votes
2 answers
74k views

How to use multiple credentials in withCredentials in Jenkins Pipeline

I have the following step in my declarative jenkins pipeline: I create script which comes from my resources/ folder using libraryResource. This script contains credentials for my autobuild user and ...
lvthillo's user avatar
  • 30k
88 votes
11 answers
176k views

Abort current build from pipeline in Jenkins

I have a Jenkins pipeline which has multiple stages, for example: node("nodename") { stage("Checkout") { git .... } stage("Check Preconditions") { ... if(!continueBuild) { // ...
seg's user avatar
  • 1,460
88 votes
2 answers
348k views

How to print a Groovy variable in Jenkins?

I have the following code within a Jenkins pipeline: stage ('Question') { try { timeout(time: 1, unit: 'MINUTES') { userInput = input message: 'Choose server to publish to:', ...
Itai Ganot's user avatar
  • 6,195
87 votes
3 answers
108k views

Updating environment global variable in Jenkins pipeline from the stage level - is it possible?

I have a Jenkinsfile with some global variables and some stages. can I update the global variable out from a stage? An example: pipeline { agent any environment { PASSWD = "...
Marvin Kallohn's user avatar
85 votes
8 answers
119k views

Can I create dynamically stages in a Jenkins pipeline?

I need to launch a dynamic set of tests in a declarative pipeline. For better visualization purposes, I'd like to create a stage for each test. Is there a way to do so? The only way to create a stage ...
david.perez's user avatar
  • 6,622
84 votes
12 answers
177k views

Jenkins: Ignore failure in pipeline build step

With jenkins build flow plugin this was possible: ignore(FAILURE){ build( "system-check-flow" ) } How to do this with Declarative Pipeline syntax?
lenkovi's user avatar
  • 1,758
84 votes
4 answers
77k views

Jenkins Pipeline: Enable timestamps in build log console

How can I display build timestamps for each line of a multi-branch pipeline project? Is it a supported feature? If yes, does it need to be enabled in the Jenkinsfile or is there a GUI option?
lanoxx's user avatar
  • 12.8k
83 votes
9 answers
158k views

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: ...
techgnosis's user avatar
  • 1,979
80 votes
11 answers
134k views

Jenkins: Pipeline sh bad substitution error

A step in my pipeline uploads a .tar to an artifactory server. I am getting a Bad substitution error when passing in env.BUILD_NUMBER, but the same commands works when the number is hard coded. The ...
Stephen Nichols's user avatar
79 votes
4 answers
87k views

How to specify when branch NOT (branch name) in jenkinsfile?

How can I specify something like the following in my Jenkinsfile? when branch not x I know how to specify branch specific tasks like: stage('Master Branch Tasks') { when { ...
HosseinK's user avatar
  • 1,307
79 votes
3 answers
111k views

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 ...
sorin's user avatar
  • 167k

1
2 3 4 5
265