DevOps Classroom Series – 29/Sept/2020

Parameters in Jenkins

  • Lets create a free style project with build parameters Preview Preview Preview
  • Save the jenkins job and click on Build Now. Inspect the console output Preview Preview
  • The parameters which we have used are referred as User Defined Parameters.
  • Internally Jenkins has lot of parameters in the form of environmental varaibles. Click on configure the job and navigate to build section Preview Preview
  • Add set statement to your invoke shell in build steps. The output is
BUILD_DISPLAY_NAME='#2'
BUILD_ID='2'
BUILD_NUMBER='2'
BUILD_TAG='jenkins-jenkinsparamdemo-2'
BUILD_URL='http://172.31.6.230:8080/job/jenkinsparamdemo/2/'
DBUS_SESSION_BUS_ADDRESS='unix:path=/run/user/113/bus'
EXECUTOR_NUMBER='0'
HOME='/var/lib/jenkins'
HUDSON_COOKIE='5edf7bc2-4aa8-4893-9b9d-41823b373889'
HUDSON_HOME='/var/lib/jenkins'
HUDSON_SERVER_COOKIE='0f64874a236d77fe'
HUDSON_URL='http://172.31.6.230:8080/'
IFS=' 	
'
IS_RELEASE_BUILD='true'
JENKINS_HOME='/var/lib/jenkins'
JENKINS_SERVER_COOKIE='0f64874a236d77fe'
JENKINS_URL='http://172.31.6.230:8080/'
JOB_BASE_NAME='jenkinsparamdemo'
JOB_DISPLAY_URL='http://172.31.6.230:8080/job/jenkinsparamdemo/display/redirect'
JOB_NAME='jenkinsparamdemo'
JOB_URL='http://172.31.6.230:8080/job/jenkinsparamdemo/'
LANG='C.UTF-8'
LOGNAME='jenkins'
MAIL='/var/mail/jenkins'
NODE_LABELS='Master master'
NODE_NAME='master'
OPTIND='1'
PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin'
PPID='744'
PS1='$ '
PS2='> '
PS4='+ '
PWD='/var/lib/jenkins/workspace/jenkinsparamdemo'
RUN_ARTIFACTS_DISPLAY_URL='http://172.31.6.230:8080/job/jenkinsparamdemo/2/display/redirect?page=artifacts'
RUN_CHANGES_DISPLAY_URL='http://172.31.6.230:8080/job/jenkinsparamdemo/2/display/redirect?page=changes'
RUN_DISPLAY_URL='http://172.31.6.230:8080/job/jenkinsparamdemo/2/display/redirect'
RUN_TESTS_DISPLAY_URL='http://172.31.6.230:8080/job/jenkinsparamdemo/2/display/redirect?page=tests'
SHELL='/bin/bash'
SHLVL='0'
USER='jenkins'
WORKSPACE='/var/lib/jenkins/workspace/jenkinsparamdemo'
WORKSPACE_TMP='/var/lib/jenkins/workspace/jenkinsparamdemo@tmp'
XDG_DATA_DIRS='/usr/local/share:/usr/share:/var/lib/snapd/desktop'
XDG_RUNTIME_DIR='/run/user/113'
XDG_SESSION_CLASS='background'
XDG_SESSION_ID='c1'
XDG_SESSION_TYPE='unspecified'
_='/usr/bin/daemon'
branch='master'
destination='/tmp'

Upstream and Downstream jobs

  • Real time relevance: Preview

  • In many cases jobs will be triggered from other jobs. In the above example the ansible deployment job will be triggered after the maven package job

  • Lets consider the Job to

    • build maven package as A
    • Deploy application using Ansbile as B
    • Execute Tests as C
  • Lets visualize this Preview

  • Now Job-B becomes downstream job for Job A and Job-C become downstream job Job-B

  • Now Job-A becomes upstream job for Job B and Job-B becomes upstream job for Job C

  • Create a jenkins job to create upstream and downstream from post build actions Preview Preview Preview Preview Preview

  • The same dependency structure can be achieved by using Build Triggers Preview

Next Steps:

  • Pipeline as a code
    • Scripted Pipelines
    • Declarative Pipelines

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin