Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dragonfly-net/1cafb6f42dbf1c553753722290f1c8ab to your computer and use it in GitHub Desktop.
Save dragonfly-net/1cafb6f42dbf1c553753722290f1c8ab to your computer and use it in GitHub Desktop.
Simple pipeline (declarative)
def GLOBALVAR="GLOBAL"
pipeline {
parameters {
choice(name:'CHOICE1', choices:["ALL", "NOTHING"], description: 'choices test')
string(name:"STRING1", defaultValue:"string default")
}
agent { node { label 'mac' } }
stages {
stage("test1") {
environment {
FOO = "bar"
}
steps {
script {
def VAR1="var1"
GLOBALVAR="inscript"
echo "3 $VAR1"
sh ("""#!/bin/bash -xe
echo "1 $GLOBALVAR"
echo "2 $FOO"
echo "3 ${params.CHOICE1}"
echo "4 $PARAM1"
echo "5 $VAR1 seen only in script block"
env
set
export
""")
}
echo "${GLOBALVAR}"
}
post {
success {
echo "SUCCESS"
echo " global in post: ${GLOBALVAR}"
}
}
}
stage ("test2") {
steps {
echo " ===== $GLOBALVAR"
script {
GLOBALVAR="step2"
dir ("./artifact") {
sh ("echo TEST >> text1.txt")
}
}
echo "$GLOBALVAR"
stash(name:"test", includes:"artifact/*")
script{sh("ls -la artifact")}
}
}
stage ("Linux step") {
agent { node { label 'linux' } }
steps {
echo "Runned on linux"
unstash("test")
script {
sh("""pwd
ls -la
ls -la artifact""")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment