Difference between revisions of "IT-SDK-Jenkins"

From wiki.samerhijazi.net
Jump to navigation Jump to search
(Jenkenfiles)
(Source)
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/
 +
 
=Coding=
 
=Coding=
 
<pre class="code">
 
<pre class="code">

Revision as of 17:26, 20 March 2020

Source

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}"
}