[JIRA] (JENKINS-58668) Doesn't create a file within docker.inside {}

7 views
Skip to first unread message

jballet@edgelab.ch (JIRA)

unread,
Jul 26, 2019, 4:20:01 AM7/26/19
to jenkinsc...@googlegroups.com
Jonathan Ballet created an issue
 
Jenkins / Bug JENKINS-58668
Doesn't create a file within docker.inside {}
Issue Type: Bug Bug
Assignee: Dominik Bartholdi
Components: config-file-provider-plugin
Created: 2019-07-26 08:18
Environment: jenkins: 2.187
config-file-provider-plugin: 3.6.2
docker-pipeline: 1.18
Labels: config-file-provider docker
Priority: Major Major
Reporter: Jonathan Ballet

Using a `configFileProvider` within a `docker.inside {}` code block doesn't create the configuration file *in* the container but on *the host* running the container.

node {
    docker.image('alpine').inside {                                                                                                                                                                                                                                         
        configFileProvider([configFile(fileId: 'test-123', targetLocation: '/foobar')]) {
            sh "cat /foobar"
        }
    }
}

Produces the following output:

[Pipeline] Start of Pipeline
[Pipeline] node
Running on qemu2 in /home/jenkins/workspace/t-jenkins_bug-config-file-docker
[Pipeline] {
[Pipeline] withDockerServer
[Pipeline] {
[Pipeline] sh
+ docker inspect -f . alpine
.
[Pipeline] withDockerContainer
qemu2 does not seem to be running inside a container
$ docker run -t -d -u 0:0 -w /home/jenkins/workspace/t-jenkins_bug-config-file-docker -v /home/jenkins/workspace/t-jenkins_bug-config-file-docker:/home/jenkins/workspace/t-jenkins_bug-config-file-docker:rw,z -v /home/jenkins/workspace/t-jenkins_bug-config-file-docker@tmp:/home/jenkins/workspace/t-jenkins_bug-config-file-docker@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** alpine cat
$ docker top e4288736bfaaa9adb71e175384021ae505f1cab767b3ef4219783097b57ffb81 -eo pid,comm
[Pipeline] {
[Pipeline] configFileProvider
provisioning config files...
copy managed file [MyCustom] to file:/foobar
[Pipeline] {
[Pipeline] echo
In the container
[Pipeline] sh
+ cat /foobar
cat: can't open '/foobar': No such file or directory
[Pipeline] echo
hudson.AbortException: script returned exit code 1
[Pipeline] }
[Pipeline] // configFileProvider
[Pipeline] }
$ docker stop --time=1 e4288736bfaaa9adb71e175384021ae505f1cab767b3ef4219783097b57ffb81
$ docker rm -f e4288736bfaaa9adb71e175384021ae505f1cab767b3ef4219783097b57ffb81
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withDockerServer
[Pipeline] echo
On the container
[Pipeline] sh
+ cat /foobar
123
456[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

(I have an additional withDockerServer around in this example, and Jenkins connects as root on the Docker host machine.)

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

jballet@edgelab.ch (JIRA)

unread,
Jul 26, 2019, 4:21:02 AM7/26/19
to jenkinsc...@googlegroups.com
Jonathan Ballet updated an issue
Change By: Jonathan Ballet
Using a `configFileProvider` within a `docker.inside {}` code block doesn't create the configuration file **in** the container but on **the host** running the container.

{code:groovy}
node {
    docker.image('alpine').inside {
                    

        configFileProvider([configFile(fileId: 'test-123', targetLocation: '/foobar')]) {
            echo "In the container"
            try {
            sh "cat /foobar"
        }
catch (Exception exc) {
                println exc
    }
}
    }

    echo "On the container"
    sh "cat /foobar"
}
{code}

Produces the following output:

{code}
{code}


(I have an additional {{withDockerServer}} around in this example, and Jenkins connects as root on the Docker host machine.)

domi@fortysix.ch (JIRA)

unread,
Aug 2, 2019, 2:38:04 AM8/2/19
to jenkinsc...@googlegroups.com
Dominik Bartholdi commented on Bug JENKINS-58668
 
Re: Doesn't create a file within docker.inside {}

hmm, good catch - need to investigate to see how this is even doable...

chad@freakingawesome.net (JIRA)

unread,
Aug 20, 2019, 10:23:02 AM8/20/19
to jenkinsc...@googlegroups.com

I've been using this plugin just fine inside docker containers. If targetLocation is set as relative to the workspace (e.g. "foobar" instead of "/foobar") then the file shows up as expected in the workspace, both inside and outside of the container.

I'd argue that this use case should not be supported. If you really want to inject a config file outside of the shared workspace folder inside the container, you could subsequently move it out of the workspace folder inside the container.

If anything, perhaps this plugin could issue a warning if targetLocation points to somewhere above the workspace directory.

domi@fortysix.ch (JIRA)

unread,
Aug 21, 2019, 2:02:02 AM8/21/19
to jenkinsc...@googlegroups.com
Dominik Bartholdi resolved as Not A Defect
 

Chad Gilbert many thanks for the detailed explanation! I fully agree and therefore will resolve this issue

Change By: Dominik Bartholdi
Status: Open Resolved
Resolution: Not A Defect
Reply all
Reply to author
Forward
0 new messages