[JIRA] (JENKINS-41923) Different pipeline steps are executed in different directories

3 views
Skip to first unread message

roberto.fasciolo@paf.com (JIRA)

unread,
Feb 10, 2017, 7:00:02 AM2/10/17
to jenkinsc...@googlegroups.com
Roberto Fasciolo created an issue
 
Jenkins / Bug JENKINS-41923
Different pipeline steps are executed in different directories
Issue Type: Bug Bug
Assignee: Andrew Bayer
Attachments: Jenkinsfile
Components: pipeline-model-definition-plugin
Created: 2017/Feb/10 11:59 AM
Environment: Jenkins 2.45, pipeline-mode-definition-plugin 1.0
Priority: Critical Critical
Reporter: Roberto Fasciolo

When running a declarative pipeline where one step is executed inside a docker image and another step doesn't the commands are executed in different directories.

For example the output of the attached Jenkinsfile is:

[Pipeline] stage
[Pipeline] { (build)
[Pipeline] node
Running on master in /var/lib/jenkins/workspace/enkins-pipeline-test_master-P4NWY5PAMN3ERY6WPQW6JSZQFPG7ON34FEGANUPSGPVVMSMYGNNA@2
[Pipeline] {
[Pipeline] sh
[enkins-pipeline-test_master-P4NWY5PAMN3ERY6WPQW6JSZQFPG7ON34FEGANUPSGPVVMSMYGNNA@2] Running shell script
+ docker inspect -f . openjdk:8u111-jdk
.
[Pipeline] withDockerContainer
$ docker run -t -d -u 108:113 -w /var/lib/jenkins/workspace/enkins-pipeline-test_master-P4NWY5PAMN3ERY6WPQW6JSZQFPG7ON34FEGANUPSGPVVMSMYGNNA@2 -v /var/lib/jenkins/workspace/enkins-pipeline-test_master-P4NWY5PAMN3ERY6WPQW6JSZQFPG7ON34FEGANUPSGPVVMSMYGNNA@2:/var/lib/jenkins/workspace/enkins-pipeline-test_master-P4NWY5PAMN3ERY6WPQW6JSZQFPG7ON34FEGANUPSGPVVMSMYGNNA@2:rw -v /var/lib/jenkins/workspace/enkins-pipeline-test_master-P4NWY5PAMN3ERY6WPQW6JSZQFPG7ON34FEGANUPSGPVVMSMYGNNA@2@tmp:/var/lib/jenkins/workspace/enkins-pipeline-test_master-P4NWY5PAMN3ERY6WPQW6JSZQFPG7ON34FEGANUPSGPVVMSMYGNNA@2@tmp:rw -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat openjdk:8u111-jdk
[Pipeline]

Unknown macro: { [Pipeline] checkout Cloning the remote Git repository ....removed.... [Pipeline] sh [enkins-pipeline-test_master-P4NWY5PAMN3ERY6WPQW6JSZQFPG7ON34FEGANUPSGPVVMSMYGNNA@2] Running shell script + pwd /var/lib/jenkins/workspace/enkins-pipeline-test_master-P4NWY5PAMN3ERY6WPQW6JSZQFPG7ON34FEGANUPSGPVVMSMYGNNA@2 [Pipeline] }

$ docker stop --time=1 b377c0539defa63fed13c99c261b700eea94e6f970e5f25b558f658e46e27b09
$ docker rm -f b377c0539defa63fed13c99c261b700eea94e6f970e5f25b558f658e46e27b09
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (image)
[Pipeline] sh
[enkins-pipeline-test_master-P4NWY5PAMN3ERY6WPQW6JSZQFPG7ON34FEGANUPSGPVVMSMYGNNA] Running shell script
+ pwd
/var/lib/jenkins/workspace/enkins-pipeline-test_master-P4NWY5PAMN3ERY6WPQW6JSZQFPG7ON34FEGANUPSGPVVMSMYGNNA
[Pipeline] script
[Pipeline]

Unknown macro: { [Pipeline] sh [enkins-pipeline-test_master-P4NWY5PAMN3ERY6WPQW6JSZQFPG7ON34FEGANUPSGPVVMSMYGNNA] Running shell script + pwd /var/lib/jenkins/workspace/enkins-pipeline-test_master-P4NWY5PAMN3ERY6WPQW6JSZQFPG7ON34FEGANUPSGPVVMSMYGNNA [Pipeline] }

[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

This creates issues when for example gradle should be run inside a docker image (in order to control the environment) but one build step generates a new docker image (so it should be run directly on the Jenkins slave host).

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

andrew.bayer@gmail.com (JIRA)

unread,
Feb 10, 2017, 6:44:01 PM2/10/17
to jenkinsc...@googlegroups.com

roberto.fasciolo@paf.com (JIRA)

unread,
Feb 11, 2017, 3:49:01 AM2/11/17
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Feb 11, 2017, 12:27:04 PM2/11/17
to jenkinsc...@googlegroups.com

D'oh!

Try adding reuseNode true to your docker - it'll then run on the same agent and workspace as the top level.

roberto.fasciolo@paf.com (JIRA)

unread,
Feb 13, 2017, 1:15:01 AM2/13/17
to jenkinsc...@googlegroups.com

roberto.fasciolo@paf.com (JIRA)

unread,
Feb 13, 2017, 1:17:02 AM2/13/17
to jenkinsc...@googlegroups.com
Roberto Fasciolo commented on Bug JENKINS-41923
 
Re: Different pipeline steps are executed in different directories

Yes, adding reuseNode true seems to work around the issue. However it's very confusing if different steps of the same pipeline are executed in different directories as it means that the second step is potentially not working on the output of the first step (therefore, IMHO, breaking the whole concept of pipeline). I attached now here a cleaned-up version of the Jenkinsfile I've been using in my real project: Jenkinsfile-real.

As you can see it first runs the gradle build (which generates a Dockerfile in the build directory), then a QA step and then it tries to generate a docker image. In the shape the pipeline is at the moment the docker image generation fails because there's no Dockerfile in the build directory.

andrew.bayer@gmail.com (JIRA)

unread,
Feb 27, 2017, 4:42:04 PM2/27/17
to jenkinsc...@googlegroups.com
Andrew Bayer resolved as Won't Fix
 

So in retrospect, I wish we'd done the reuseNode behavior as the default from the start, but we didn't. Since we didn't, I'm very wary of changing that default behavior, in case someone else is working under the assumption of that behavior. I'm not opposed to revisiting this in the future, I just don't want to break any existing jobs out there.

Change By: Andrew Bayer
Status: Open Resolved
Resolution: Won't Fix

bitwiseman@gmail.com (JIRA)

unread,
Oct 22, 2019, 11:24:36 PM10/22/19
to jenkinsc...@googlegroups.com
Liam Newman closed an issue as Won't Fix
 

Bulk closing resolved issues.

Change By: Liam Newman
Status: Resolved Closed
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages