Difference between revisions of "IT-SDK-Jenkins"

From wiki.samerhijazi.net
Jump to navigation Jump to search
(Jenkinsfile/Pipeline)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Source==
+
=Source=
 
* 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://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=
Line 23: Line 28:
 
}
 
}
 
</pre>
 
</pre>
=Jenkenfiles=
+
=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">
 
<pre class="code">
 
pipeline {
 
pipeline {
Line 32: Line 39:
 
       APP = 'application'
 
       APP = 'application'
 
       VERSION = 't.b.d.'
 
       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 {
 
   options {
 
       buildDiscarder(logRotator(numToKeepStr: '15'))
 
       buildDiscarder(logRotator(numToKeepStr: '15'))
Line 38: Line 51:
 
   stages {                 
 
   stages {                 
 
       stage('Environment') {           
 
       stage('Environment') {           
 +
        when {
 +
            expression { params.REQUESTED_ACTION == 'greeting' }
 +
        }
 
         steps {                 
 
         steps {                 
 
    echo "Applacation: ${APP} or ${env.APP}"
 
    echo "Applacation: ${APP} or ${env.APP}"

Latest revision as of 15:11, 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.'
      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}"
}