Difference between revisions of "IT-SDK-Jenkins"
(→Coding) |
|||
| Line 21: | Line 21: | ||
} | } | ||
</pre> | </pre> | ||
| + | =Jenkenfiles= | ||
| + | pipeline { | ||
| + | agent { | ||
| + | label 'nodejs10' | ||
| + | } | ||
| + | |||
| + | environment { | ||
| + | APP = 'application' | ||
| + | VERSION = 't.b.d.' | ||
| + | } | ||
| + | |||
| + | options { | ||
| + | buildDiscarder(logRotator(numToKeepStr: '15')) | ||
| + | } | ||
| + | |||
| + | stages { | ||
| + | stage('Environment') { | ||
| + | steps { | ||
| + | echo "Applacation: ${APP} or ${env.APP}" | ||
| + | sh 'echo "Lib-Version: ${LIB_VERSION}"' | ||
| + | echo "##################################" | ||
| + | setVersion() | ||
| + | echo "##################################" | ||
| + | script { | ||
| + | env.LIB_VERSION = "newValue" | ||
| + | } | ||
| + | sh 'export AWESOME_FILE=$AWESOME_BUILD/the_file' | ||
| + | sh 'echo $AWESOME_FILE' // But it won't show up here! | ||
| + | // However, in a single sh command it will work. | ||
| + | sh ''' | ||
| + | export AWESOME_FILE=$AWESOME_BUILD/the_file | ||
| + | echo $AWESOME_FILE | ||
| + | ''' | ||
| + | } | ||
| + | } | ||
| + | stage('Build-Angular') { | ||
| + | steps { | ||
| + | //build job: 'test', parameters:[string(name: 'LIB_VERSION', value: "${LIB_VERSION}")], wait: false | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | def setVersion() { | ||
| + | LIB_VERSION = 'Samer' | ||
| + | echo "Lib-Version: ${LIB_VERSION}" | ||
| + | } | ||
Revision as of 16:39, 20 March 2020
Source
- src: https://jenkins.io/doc/book/pipeline/syntax/
- src: https://jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
Coding
def username = 'Jenkins'
echo 'Hello Mr. ${username}'
echo "I said, Hello Mr. ${username}"
...
Hello Mr. ${username}
I said, Hello Mr. Jenkins
environment {
APP = "${env.APP}-${env.BRANCH_NAME}"
}
steps {
sh 'echo "Name=${APP}"'
echo "Running ${APP} on ${env.APP}"
}
Jenkenfiles
pipeline {
agent {
label 'nodejs10'
}
environment {
APP = 'application'
VERSION = 't.b.d.'
}
options {
buildDiscarder(logRotator(numToKeepStr: '15'))
}
stages {
stage('Environment') { steps { echo "Applacation: ${APP} or ${env.APP}" sh 'echo "Lib-Version: ${LIB_VERSION}"' echo "##################################" setVersion() echo "##################################" script { env.LIB_VERSION = "newValue" } sh 'export AWESOME_FILE=$AWESOME_BUILD/the_file' sh 'echo $AWESOME_FILE' // But it won't show up here! // However, in a single sh command it will work. sh export AWESOME_FILE=$AWESOME_BUILD/the_file echo $AWESOME_FILE
}
}
stage('Build-Angular') { steps { //build job: 'test', parameters:[string(name: 'LIB_VERSION', value: "${LIB_VERSION}")], wait: false
}
}
}
} def setVersion() {
LIB_VERSION = 'Samer'
echo "Lib-Version: ${LIB_VERSION}" }