0

I have the following pipeline:

    pipeline {
    agent any
    environment {
        branch = 'master'
        scmUrl = 'ssh://git@myrepo.git'
        serverPort = '22'
    }
    stages {
        stage('Stage 1') {
            steps {
                sh '/var/jenkins_home/contarpalabras.sh'
            }
        }
    }
}

I want to change the pipeline to "scripted pipeline" in order to use try / catch blocks and have better error management. However i did not find how the equivalent to environment block in official documentation.

ras212
  • 67
  • 1
  • 5

1 Answers1

1

You can use the withEnv block like:

    node {
    withEnv(['DISABLE_AUTH=true',
             'DB_ENGINE=sqlite']) {
        stage('Build') {
            sh 'printenv'
        }
    }
}

This info is also in the official documentation : https://jenkins.io/doc/pipeline/tour/environment/#

marxmacher
  • 591
  • 3
  • 20