Difference between revisions of "IT-SDK-Jenkins"
Jump to navigation
Jump to search
(→Jenkinsfile/Pipeline) |
|||
| (15 intermediate revisions by 2 users not shown) | |||
| Line 2: | Line 2: | ||
* src: https://jenkins.io/doc/book/pipeline/syntax/ | * src: https://jenkins.io/doc/book/pipeline/syntax/ | ||
* src: https://jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables | * src: https://jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables | ||
| + | * src: https://e.printstacktrace.blog/jenkins-pipeline-environment-variables-the-definitive-guide/ | ||
| + | * src: https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables | ||
| + | * ${YOUR_JENKINS_URL}/pipeline-syntax/globals#env | ||
| + | |||
| + | =Docker= | ||
| + | See Docker-Section | ||
| + | |||
=Coding= | =Coding= | ||
<pre class="code"> | <pre class="code"> | ||
| Line 19: | Line 26: | ||
sh 'echo "Name=${APP}"' | sh 'echo "Name=${APP}"' | ||
echo "Running ${APP} on ${env.APP}" | echo "Running ${APP} on ${env.APP}" | ||
| + | } | ||
| + | </pre> | ||
| + | =Jenkinsfile/Pipeline= | ||
| + | * src: https://jenkins.io/doc/book/pipeline/syntax/ | ||
| + | * src: https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables | ||
| + | <pre class="code"> | ||
| + | pipeline { | ||
| + | agent { | ||
| + | label 'nodejs10' | ||
| + | } | ||
| + | environment { | ||
| + | APP = 'application' | ||
| + | VERSION = 't.b.d.' | ||
| + | AWS_ACCESS_KEY_ID = credentials('jenkins-aws-secret-key-id') | ||
| + | } | ||
| + | parameters { | ||
| + | choice(choices: ['greeting' , 'silence'],description: '',name: 'REQUESTED_ACTION') | ||
| + | string(name: 'DEPLOY_ENV', defaultValue: 'staging', description: '') | ||
| + | choice(name: 'CHOICE', choices: ['One', 'Two', 'Three'], description: 'Pick something') | ||
| + | } | ||
| + | options { | ||
| + | buildDiscarder(logRotator(numToKeepStr: '15')) | ||
| + | } | ||
| + | stages { | ||
| + | stage('Environment') { | ||
| + | when { | ||
| + | expression { params.REQUESTED_ACTION == 'greeting' } | ||
| + | } | ||
| + | steps { | ||
| + | echo "Applacation: ${APP} or ${env.APP}" | ||
| + | sh 'echo "Lib-Version: ${LIB_VERSION}"' | ||
| + | echo "##################################" | ||
| + | setVersion() | ||
| + | echo "##################################" | ||
| + | script { | ||
| + | env.VERSION = "init" | ||
| + | echo "Version: ${env.VERSION}" | ||
| + | env.VERSION = "newValue" | ||
| + | echo "Version: ${env.VERSION}" | ||
| + | } | ||
| + | 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 | ||
| + | ''' | ||
| + | withEnv(["BUILD_NUMBER=1"]) { | ||
| + | echo "BUILD_NUMBER = ${env.BUILD_NUMBER}" // prints "BUILD_NUMBER = 1" | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | 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}" | ||
} | } | ||
</pre> | </pre> | ||
Latest revision as of 15:11, 21 June 2021
Contents
Source
- src: https://jenkins.io/doc/book/pipeline/syntax/
- src: https://jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
- src: https://e.printstacktrace.blog/jenkins-pipeline-environment-variables-the-definitive-guide/
- src: https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
- ${YOUR_JENKINS_URL}/pipeline-syntax/globals#env
Docker
See Docker-Section
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}"
}
Jenkinsfile/Pipeline
- src: https://jenkins.io/doc/book/pipeline/syntax/
- src: https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
pipeline {
agent {
label 'nodejs10'
}
environment {
APP = 'application'
VERSION = 't.b.d.'
AWS_ACCESS_KEY_ID = credentials('jenkins-aws-secret-key-id')
}
parameters {
choice(choices: ['greeting' , 'silence'],description: '',name: 'REQUESTED_ACTION')
string(name: 'DEPLOY_ENV', defaultValue: 'staging', description: '')
choice(name: 'CHOICE', choices: ['One', 'Two', 'Three'], description: 'Pick something')
}
options {
buildDiscarder(logRotator(numToKeepStr: '15'))
}
stages {
stage('Environment') {
when {
expression { params.REQUESTED_ACTION == 'greeting' }
}
steps {
echo "Applacation: ${APP} or ${env.APP}"
sh 'echo "Lib-Version: ${LIB_VERSION}"'
echo "##################################"
setVersion()
echo "##################################"
script {
env.VERSION = "init"
echo "Version: ${env.VERSION}"
env.VERSION = "newValue"
echo "Version: ${env.VERSION}"
}
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
'''
withEnv(["BUILD_NUMBER=1"]) {
echo "BUILD_NUMBER = ${env.BUILD_NUMBER}" // prints "BUILD_NUMBER = 1"
}
}
}
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}"
}