0

I have a test project for end2end tests based on Nightwatch.js that is an NodeJS framework. I want to use 'Jenkinsfile' for my project to build a pipeline for my end2end tests to execute them over a Jenkins in a Docker container. So, I want to start a Docker container and execute the tests inside this Docker container. And this should be realized over a Jenkinsfile. Everything is perfect when I don't use a Jenkinsfile but directly use shell commands in a manually created job. While using Jenkinsfile I get an MultipleCompilationErrorsException while running the pipeline and I don't know why.

This is my Jenkinsfile:

pipeline {
  agent any

  parameters {
    text(defaultValue: 'grme/nightwatch-chrome-firefox:0.0.3', description: '', name: 'docker_image')
    text(defaultValue: 'npm-test-chrome', description: '', name: 'run_script_method')
    text(defaultValue: '/Applications/Docker.app/Contents/Resources/bin/docker', description: '', name: 'docker')
  }

  stages {
    stage('Test') {
      steps {
        sh 'sudo chmod -R 777 $(pwd)'
        echo "------ stop all Docker containers ------"
        sh '(sudo ${params.docker} stop $(sudo ${params.docker} ps -a -q) || echo "------ all Docker containers are still stopped ------")'
        echo "------ remove all Docker containers ------"
        sh '(sudo ${params.docker} rm $(sudo ${params.docker} ps -a -q) || sudo echo "------ all Docker containers are still removed ------")'
        echo "------ pull Docker image from Docker Cloud ------"
        sh 'sudo ${params.docker} pull "${params.docker_image}"'
        echo "------ start Docker container from image ------"
        sh 'sudo ${params.docker} run -d -t -i -v $(pwd):/my_tests/ "${params.docker_image}" /bin/bash'
        echo "------ execute end2end tests on Docker container ------"
        sh 'sudo ${params.docker} exec -i $(sudo ${params.docker} ps --format "{{.Names}}") bash -c "cd /my_tests && xvfb-run --server-args='-screen 0 1600x1200x24' npm run ${params.run_script_method} || true && google-chrome --version && firefox --version"'
        echo "------ cleanup all temporary files ------"
        sh 'sudo rm -Rf $(pwd)/tmp-*'
        sh 'sudo rm -Rf $(pwd)/.com.google*'
        sh 'sudo rm -Rf $(pwd)/rust_mozprofile*'
        sh 'sudo rm -Rf $(pwd)/.org.chromium*'
        echo "------ stop all Docker containers again ------"
        sh '(sudo ${params.docker} stop $(sudo ${params.docker} ps -a -q) || sudo echo "------ all Docker containers are still stopped ------")'
        echo "------ remove all Docker containers again ------"
        sh '(sudo ${params.docker} rm $(sudo ${params.docker} ps -a -q) || sudo echo "------ all Docker containers are still removed ------")'
      }
    }
  }
}

And this is the exception I get when running the pipeline:

Started by user GRme
 > git rev-parse --is-inside-work-tree # timeout=10
Setting origin to https://github.com/GRme/e2e-web-tests
 > git config remote.origin.url https://github.com/GRme/e2e-web-tests # timeout=10
Fetching origin...
Fetching upstream changes from origin
 > git --version # timeout=10
using GIT_ASKPASS to set credentials 
 > git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/*
Seen branch in repository origin/master
Seen 1 remote branch
Obtained Jenkinsfile from 0eb7d8c437df1efc56e46171d945e7f2806b838b
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 23: Expected a symbol @ line 23, column 9.
           sh 'sudo ${params.docker} exec -i $(sudo ${params.docker} ps --format "{{.Names}}") bash -c "cd /my_tests && xvfb-run --server-args='-screen 0 1600x1200x24' npm run ${params.run_script_method} || true && google-chrome --version && firefox --version"'
           ^

1 error

    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
    at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
    at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:129)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:123)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:516)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:479)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:269)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:419)
Finished: FAILURE

What do I wrong and how can I solve this exception?

2
  • 1
    I suspect the fact that the single quotes here -server-args='...' are nested within the sh '...' Commented Aug 23, 2017 at 9:44
  • Yes I think you are right, but it should be possible to do something like this. What should I do? Commented Aug 23, 2017 at 9:54

1 Answer 1

1

After escaping the ' in the line, the pipeline has no syntax error anymore :)

sh 'sudo ${params.docker} exec -i $(sudo ${params.docker} ps --format "{{.Names}}") bash -c "cd /my_tests && xvfb-run --server-args=\'-screen 0 1600x1200x24\' npm run ${params.run_script_method} || true && google-chrome --version && firefox --version"'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.