Pipeline Examples

pipeline examples

pipeline {
  agent {
    dockerfile {
      /*
       * This assumes that a "Dockerfile" is in the current workspace
       * A new container will be build with the args below and the pipeline will run inside that container.
       */
      args "-v /tmp:/tmp -p 8000:8000"
    }
  }
  stages {
    stage("foo") {
      steps {
        sh 'cat /hi-there'
        sh 'echo "The answer is 42"'
      }
    }
  }
}

pipeline {
  agent any

  environment {
    // FOO will be available in entire pipeline
    FOO = "PIPELINE"
  }

  stages {
    stage("local") {
      environment {
        // BAR will only be available in this stage
        BAR = "STAGE"
      }
      steps {
        sh 'echo "FOO is $FOO and BAR is $BAR"'
      }
    }
    stage("global") {
      steps {
        sh 'echo "FOO is $FOO and BAR is $BAR"'
      }
    }
  }
}

Last updated