Link Search Menu Expand Document

Jenkins

Getting started with the Guided Tour

{
    apt update
    apt install openjdk-11-jre -y

    java -version
}
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2, mixed mode)
{
    wget https://get.jenkins.io/war-stable/2.289.3/jenkins.war
    java -jar jenkins.war --httpPort=8080
}
...

Running from: /root/jenkins.war
webroot: $user.home/.jenkins
2021-07-29 07:43:46.288+0000 [id=1]     INFO    org.eclipse.jetty.util.log.Log#initialized: Logging initialized @6119ms to org.eclipse.jetty.util.log.JavaUtilLog
2021-07-29 07:43:47.634+0000 [id=1]     INFO    winstone.Logger#logInternal: Beginning extraction from war file
2021-07-29 07:43:58.950+0000 [id=1]     WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2021-07-29 07:43:59.548+0000 [id=1]     INFO    org.eclipse.jetty.server.Server#doStart: jetty-9.4.41.v20210516; built: 2021-05-16T23:56:28.993Z; git: 98607f93c7833e7dc59489b13f3cb0a114fb9f4c; jvm 11.0.11+9-Ubuntu-0ubuntu2
2021-07-29 07:44:02.581+0000 [id=1]     INFO    o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2021-07-29 07:44:02.979+0000 [id=1]     INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2021-07-29 07:44:02.981+0000 [id=1]     INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2021-07-29 07:44:02.992+0000 [id=1]     INFO    o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 660000ms
2021-07-29 07:44:09.025+0000 [id=1]     INFO    hudson.WebAppMain#contextInitialized: Jenkins home directory: /root/.jenkins found at: $user.home/.jenkins
Fontconfig warning: ignoring UTF-8: not a valid region tag
2021-07-29 07:44:12.210+0000 [id=1]     INFO    o.e.j.s.handler.ContextHandler#doStart: Started w.@71ad3d8a{Jenkins v2.289.3,/,file:///root/.jenkins/war/,AVAILABLE}{/root/.jenkins/war}
2021-07-29 07:44:12.585+0000 [id=1]     INFO    o.e.j.server.AbstractConnector#doStart: Started ServerConnector@3b7ff809{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2021-07-29 07:44:12.628+0000 [id=1]     INFO    org.eclipse.jetty.server.Server#doStart: Started @32431ms
2021-07-29 07:44:12.646+0000 [id=24]    INFO    winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2021-07-29 07:44:16.452+0000 [id=31]    INFO    jenkins.InitReactorRunner$1#onAttained: Started initialization
2021-07-29 07:44:16.690+0000 [id=35]    INFO    jenkins.InitReactorRunner$1#onAttained: Listed all plugins
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$2 (file:/root/.jenkins/war/WEB-INF/lib/guice-4.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$2
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2021-07-29 07:44:32.275+0000 [id=31]    INFO    jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2021-07-29 07:44:32.336+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Started all plugins
2021-07-29 07:44:32.577+0000 [id=32]    INFO    jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2021-07-29 07:44:42.424+0000 [id=33]    INFO    jenkins.InitReactorRunner$1#onAttained: System config loaded
2021-07-29 07:44:42.432+0000 [id=36]    INFO    jenkins.InitReactorRunner$1#onAttained: System config adapted
2021-07-29 07:44:42.442+0000 [id=33]    INFO    jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2021-07-29 07:44:42.457+0000 [id=30]    INFO    jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2021-07-29 07:44:42.712+0000 [id=49]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Download metadata
2021-07-29 07:44:42.994+0000 [id=49]    INFO    hudson.util.Retrier#start: Attempt #1 to do the action check updates server
2021-07-29 07:44:49.029+0000 [id=32]    INFO    jenkins.install.SetupWizard#init:

*************************************************************
*************************************************************
*************************************************************

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

34789ca5c0aa4036a46bf0ca254a0f89

This may also be found at: /root/.jenkins/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

2021-07-29 07:46:48.904+0000 [id=30]    INFO    jenkins.InitReactorRunner$1#onAttained: Completed initialization
2021-07-29 07:46:49.170+0000 [id=23]    INFO    hudson.WebAppMain$3#run: Jenkins is fully up and running
2021-07-29 07:46:51.107+0000 [id=49]    INFO    h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
2021-07-29 07:46:51.121+0000 [id=49]    INFO    hudson.util.Retrier#start: Performed the action check updates server successfully at the attempt #1
2021-07-29 07:46:51.180+0000 [id=49]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Download metadata. 128,437 ms
2021-07-29 07:49:27.149+0000 [id=70]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Periodic background build discarder
2021-07-29 07:49:27.158+0000 [id=70]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Periodic background build discarder. 4 ms

Creating your first Pipeline

  • Install Docker and Docker Pipeline plugins
pipeline {
    agent { docker { image 'node:14-alpine' } }
    stages {
        stage('build') {
            steps {
                sh 'npm --version'
            }
        }
    }
}

Running multiple steps

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                sh 'echo "Hello World"'
                sh '''
                    echo "Multiline shell steps works too"
                    ls -lah
                '''
            }
        }
    }
}

Finishing up

When the Pipeline has finished executing, you may need to run clean-up steps or perform some actions based on the outcome of the Pipeline. These actions can be performed in the post section.

pipeline {
    agent any
    stages {
        stage('Test') {
            steps {
                sh 'echo "Fail!"; exit 1'
            }
        }
    }
    post {
        always {
            echo 'This will always run'
        }
        success {
            echo 'This will run only if successful'
        }
        failure {
            echo 'This will run only if failed'
        }
        unstable {
            echo 'This will run only if the run was marked as unstable'
        }
        changed {
            echo 'This will run only if the state of the Pipeline has changed'
            echo 'For example, if the Pipeline was previously failing but is now successful'
        }
    }
}

Defining execution environments

Using environment variables