Wednesday, May 22, 2019

Jenkins - Installation


  1. Download the war
    wget http://ftp-chi.osuosl.org/pub/jenkins/war/2.161/jenkins.war
  2. Start it
    nohup java -Duser.home=/opt/jenkins/jenkins_home -Duser.timezone=America/Chicago -jar lib/jenkins.war --httpsPort=8080 &
  3. Configure it
    http://localhost:8080
  4. Blue Ocean & Create pipeline
    http://localhost:8080/blue
  5. Create slaves/agents
    Dashboard > Manage Jenkins > Mange Nodes > ....
    The nodes:
    1. can be any type of machine
    2. can be manually activate/inactivate

Tuesday, May 21, 2019

Jenkins - Pipeline Syntax

The Jenkins Pipeline Syntax page (https://jenkins.io/doc/book/pipeline/syntax/)

Agent - specifies where the entire Pipeline, or a specific stage, will execute in the Jenkins environment depending on where the agent section is placed. It support docker and dockerfile in it.

Postdefines one or more additional steps that are run upon the completion of a Pipeline’s or stage’s run (depending on the location of the post section within the Pipeline). post can support any of of the following post-condition blocks: alwayschangedfixedregressionabortedfailuresuccessunstableunsuccessful, and cleanup

Stags - containing a sequence of one or more stage directives.

Steps - the steps section defines a series of one or more steps to be executed in a given stage directive.

Environment - specifies a sequence of key-value pairs which will be defined as environment variables for the all steps, or stage-specific steps, depending on where the environment directive is located within the Pipeline.
environment {
       SERVICE_CREDS = credentials('my-prefined-username-password')
}
Options/Parameters

Triggers - support cron, pollSCM and upstream 
When Pipeline to determine whether the stage should be executed depending on the given condition.

Sequential/Parallel 
pipeline {
    agent any
    options {
        parallelsAlwaysFailFast()
    }
    stages {
        stage('Non-Parallel Stage') {
            steps {
                echo 'This stage will be executed first.'
            }
        }
        stage('Parallel Stage') {
            when {
                branch 'master'
            }
            parallel {
                stage('Branch A') {
                    agent {
                        label "for-branch-a"
                    }
                    steps {
                        echo "On Branch A"
                    }
                }
                stage('Branch B') {
                    agent {
                        label "for-branch-b"
                    }
                    steps {
                        echo "On Branch B"
                    }
                }
            }
        }
    }