Search code examples
jenkinsgroovyjenkins-pipeline

Multistep shell commands on Jenkins pipeline


I have a jenkins job that has a shell step with following commands. It runs great!

sudo yum install python36
virtualenv -p python3 test
source test/bin/activate
<some other command>

Now I want to make this into a pipeline. How do I write the same in groovy? I tried using syntax like this but it fails:

stage('Test') {
        steps {
            sh 'sudo yum install python36'
            sh 'virtualenv -p python3 test'
        }
    }

Solution

  • In order to to execute multiple shell commands you need to wrap them in a pair of three single quotes ''':

    stage('Test') {
            steps {
                sh '''
                   sudo yum install python36
                   virtualenv -p python3 test
                   '''
            }
    }