Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins shell script unexpected end of file

I started a new Jenkins server in the following way using Docker:

$ docker run -p 8081:8080 -p 50000:50000 -v "${PWD}"/jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -d --name jenkins jenkins/jenkins:lts

I want to use it for a simple pipeline executing a shell script that is building another Docker container. This is why I am mounting the docker.sock as well. However, using a Jenkinsfile like the following:

pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                echo "####### builds: #######"
                sh "(exit 1) || true # whatever I write here, it always fails"
            }
        }
    }
}

I always get an error like:

Print Message -- ####### builds: ####### -- (self time 7ms)
####### builds: ####### 

Shell Script -- (exit 1) || true -- (self time 18s)
[X's Pipeline] Running shell script sh: 1: Syntax error: end of file unexpected (expecting "done")
process apparently never started in /var/jenkins_home/workspace/X's Pipeline@tmp/durable-f294beff 

replacing the sh line by any of the following did produce a similar error message and lead the build process to fail as well:

  • sh "pwd;"
  • sh "echo 'hello';"
  • sh ./build.sh;"
  • sh ```
    #!/bin/sh
    echo hello
    ```
    
  • … I tried many more

But when I remove the sh line, the build succeeds. I have successfully done this before on other systems. Is there anything I am missing here?


  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-514.26.2.el7.x86_64
      Architecture: x86-64

    Docker version: 17.05.0-ce, build 89658be
like image 580
cocoseis Avatar asked Sep 01 '25 01:09

cocoseis


1 Answers

It turned out, the name of the pipeline X's Pipeline has an '; and Jenkins is not escaping it or warning the user when using the GUI !!!!!!. After renaming the pipeline to X Pipeline it works just fine. Knowing this before could have saved me hours of trouble…

like image 62
cocoseis Avatar answered Sep 02 '25 14:09

cocoseis