Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save darinpope/cfcd3f20f5acc10fe1ccd5b3e4b8a5c0 to your computer and use it in GitHub Desktop.
Save darinpope/cfcd3f20f5acc10fe1ccd5b3e4b8a5c0 to your computer and use it in GitHub Desktop.

Gist for https://youtu.be/41uUsWQjKRw

Scripted pipeline example

def animal="cat"
node {
  stage('hello') {
    echo animal
    animal = "dog"
  }
  stage('goodbye') {
    echo animal
  }
}

Declarative pipeline example

def animal="cat"
pipeline {
  agent any
  stages {
    stage("hello") {
      steps {
        script {
          echo animal
          animal = "dog";
        }
      }
    }
    stage("goodbye") {
      steps {
        script {
          echo animal
        }
      }
    }
  }
}
@BenPortner
Copy link

BenPortner commented Mar 14, 2024

I've been looking for a way to achieve this for hours! Thank you very much for posting a working solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment