Difference between revisions of "IT-SDK-Jenkins"

From wiki.samerhijazi.net
Jump to navigation Jump to search
(Source)
(Source)
Line 3: Line 3:
 
* 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://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
 
* ${YOUR_JENKINS_URL}/pipeline-syntax/globals#env
  

Revision as of 15:09, 21 June 2021

Source

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

pipeline {
   agent {
      label 'nodejs10'
   }
   environment {
      APP = 'application'
      VERSION = 't.b.d.'
   }
   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}"
}