[JIRA] (JENKINS-57321) Cannot set diferent shebang in shell in Docker in pipeline

3 views
Skip to first unread message

ovidiu.b13@gmail.com (JIRA)

unread,
May 3, 2019, 8:33:02 AM5/3/19
to jenkinsc...@googlegroups.com
Ovidiu-Florin Bogdan created an issue
 
Jenkins / Bug JENKINS-57321
Cannot set diferent shebang in shell in Docker in pipeline
Issue Type: Bug Bug
Assignee: Carlos Sanchez
Components: docker, pipeline
Created: 2019-05-03 12:32
Environment: Jenkins 2.164.2
Docker Pipeline Plugin 1.18
Pipeline Plugin 2.6
Blue Ocean Plugin 1.14.0
Labels: user-experience pipeline
Priority: Major Major
Reporter: Ovidiu-Florin Bogdan

With the following pipeline:

pipeline{
    agent none
    stages{
        stage('deploy') {
            agent {
                docker {
                    image 'alpine:latest'
                }
            }
            steps {
                sh """
                    #!/bin/sh
                    echo foo
                """
            }
        }
    }
}

I get the following output:

[Pipeline] Start of Pipeline (hide)
[Pipeline] stage
[Pipeline] { (deploy)
[Pipeline] node
Running on Auto-launched Jenkins NextGen build slave (i-XXX) in /home/jenkins/workspace/XXX
[Pipeline] {
[Pipeline] checkout
Git checkout logs...
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ docker inspect -f . alpine:latest

Error: No such object: alpine:latest
[Pipeline] sh
+ docker pull alpine:latest
latest: Pulling from library/alpine
bdf0201b3a05: Already exists
Digest: sha256:28ef97b8686a0b5399129e9b763d5b7e5ff03576aa5580d6f4182a49c5fe1913
Status: Downloaded newer image for alpine:latest
[Pipeline] withDockerContainer
Auto-launched Jenkins XXX build slave (i-XXX) does not seem to be running inside a container
$ docker run -t -d -u 5130:5130
    -w /home/jenkins/workspace/XXX
    -v /home/jenkins/workspace/XXX:/home/jenkins/workspace/XXX:rw,z
    -v /home/jenkins/workspace/XXX@tmp:/home/jenkins/workspace/XXX@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 ********
    alpine:latest cat
[Pipeline] {
[Pipeline] sh
$ docker top 9d50ea59f9db9cc74075029184bf24c1bff53d180cee8d5b80f291d0c9c3c75d -eo pid,comm
sh: /bin/bash: not found
[Pipeline] }
$ docker stop --time=1 9d50ea59f9db9cc74075029184bf24c1bff53d180cee8d5b80f291d0c9c3c75d
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline

The Alpine docker image does not contain bash, only sh.

According to https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#sh-shell-script and interpreter selector may be used, but gives no context as to where to place that selector, just shows a shebang. This leaves to believe that my pipeline example is correct.

The CloudBees support page https://support.cloudbees.com/hc/en-us/articles/215171038-How-do-I-run-a-different-Shell-interpreter-in-a-Pipeline-Script- gives an example, of setting the shebang, but it does so in the node block, which is unrelated to a pipeline. So again the example isn't clear.

How can one change the Shell used in a job, other than changing the Jenkins system wide default shell?

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

jenkins-ci@carlossanchez.eu (JIRA)

unread,
May 3, 2019, 8:48:02 AM5/3/19
to jenkinsc...@googlegroups.com
Carlos Sanchez commented on Bug JENKINS-57321
 
Re: Cannot set diferent shebang in shell in Docker in pipeline

have you tried without the new line?

sh """#!/bin/sh

ovidiu.b13@gmail.com (JIRA)

unread,
May 7, 2019, 6:45:02 AM5/7/19
to jenkinsc...@googlegroups.com
Ovidiu-Florin Bogdan closed an issue as Not A Defect
 
Change By: Ovidiu-Florin Bogdan
Status: Open Closed
Resolution: Not A Defect

ovidiu.b13@gmail.com (JIRA)

unread,
May 7, 2019, 6:45:02 AM5/7/19
to jenkinsc...@googlegroups.com
Ovidiu-Florin Bogdan commented on Bug JENKINS-57321
 
Re: Cannot set diferent shebang in shell in Docker in pipeline

I have tried just now. It works. I didn't think the newline after """ gets into the executed script.

Thank you Carlos Sanchez.

Reply all
Reply to author
Forward
0 new messages