Showing posts with label Jenkins. Show all posts
Showing posts with label Jenkins. Show all posts

Sunday, April 12, 2026

Install Jenkins via Docker and setup access via ssh

 


Install Jenkins via Docker 


dave@fedora:/git/devops-docker$ sudo docker run --name jenkins-test -p 8080:8080 -p 50000:50000 -d jenkins/jenkins:lts
[sudo] password for dave: 
Unable to find image 'jenkins/jenkins:lts' locally
lts: Pulling from jenkins/jenkins
53c88f1dfeb7: Pull complete 
4d2125ccf71c: Pull complete 
69503609dc01: Pull complete 
6da7907f70f4: Pull complete 
6327a7366a6f: Pull complete 
01938f7c040b: Pull complete 
b7b154fd69a1: Pull complete 
876217fdee20: Pull complete 
fbae626c1b7a: Pull complete 
b19825c62ed8: Pull complete 
ec7478903548: Pull complete 
e682a95ad036: Pull complete 
Digest: sha256:c4098086090ca98491d4bf66182f5e3b015a8232f2acf2df209a212a5801aa8e
Status: Downloaded newer image for jenkins/jenkins:lts
16c87f857d22f7a0be645a6a1cd88633bfef9b381a03c9061ad723acc4acc33c


Get admin password 

dave@fedora:/git/devops-docker$ sudo docker logs jenkins-test
Running from: /usr/share/jenkins/jenkins.war
webroot: /var/jenkins_home/war
2026-04-12 13:46:37.724+0000 [id=1]    INFO    winstone.Logger#logInternal: Beginning extraction from war file
2026-04-12 13:46:38.325+0000 [id=1]    WARNING    o.e.j.ee9.nested.ContextHandler#setContextPath: Empty contextPath
2026-04-12 13:46:38.359+0000 [id=1]    INFO    org.eclipse.jetty.server.Server#doStart: jetty-12.1.5; built: 2025-12-03T22:18:24.732Z; git: 4905d09d7b6801e792d7b73946cf7b66e4be25d6; jvm 21.0.9+10-LTS
2026-04-12 13:46:38.654+0000 [id=1]    INFO    o.e.j.e.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.ee9.jsp.JettyJspServlet
2026-04-12 13:46:38.699+0000 [id=1]    INFO    o.e.j.s.DefaultSessionIdManager#doStart: Session workerName=node0
2026-04-12 13:46:38.909+0000 [id=1]    INFO    hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2026-04-12 13:46:38.979+0000 [id=1]    INFO    o.e.j.s.handler.ContextHandler#doStart: Started oeje9n.ContextHandler$CoreContextHandler@3681037{Jenkins v2.541.3,/,b=file:///var/jenkins_home/war/,a=AVAILABLE,h=oeje9n.ContextHandler$CoreContextHandler$CoreToNestedHandler@2459319c{STARTED}}
2026-04-12 13:46:38.990+0000 [id=1]    INFO    o.e.j.server.AbstractConnector#doStart: Started oejs.ServerConnector@2aa6311a{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2026-04-12 13:46:38.991+0000 [id=1]    INFO    org.eclipse.jetty.server.Server#doStart: Started oejs.Server@78525ef9{STARTING}[12.1.5,sto=0] @633ms
2026-04-12 13:46:38.992+0000 [id=43]    INFO    winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2026-04-12 13:46:39.073+0000 [id=42]    INFO    jenkins.model.Jenkins#<init>: Starting version 2.541.3
2026-04-12 13:46:39.122+0000 [id=51]    INFO    jenkins.InitReactorRunner$1#onAttained: Started initialization
2026-04-12 13:46:39.132+0000 [id=72]    INFO    jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2026-04-12 13:46:39.707+0000 [id=51]    INFO    jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2026-04-12 13:46:39.711+0000 [id=51]    INFO    jenkins.InitReactorRunner$1#onAttained: Started all plugins
2026-04-12 13:46:39.712+0000 [id=68]    INFO    jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2026-04-12 13:46:39.837+0000 [id=52]    INFO    jenkins.InitReactorRunner$1#onAttained: System config loaded
2026-04-12 13:46:39.837+0000 [id=59]    INFO    jenkins.InitReactorRunner$1#onAttained: System config adapted
2026-04-12 13:46:39.838+0000 [id=69]    INFO    jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2026-04-12 13:46:39.839+0000 [id=69]    INFO    jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2026-04-12 13:46:39.857+0000 [id=86]    INFO    hudson.util.Retrier#start: Attempt #1 to do the action check updates server
2026-04-12 13:46:40.152+0000 [id=63]    INFO    jenkins.install.SetupWizard#init: 
[LF]> 
[LF]> *************************************************************
[LF]> *************************************************************
[LF]> *************************************************************
[LF]> 
[LF]> Jenkins initial setup is required. An admin user has been created and a password generated.
[LF]> Please use the following password to proceed to installation:
[LF]> 
[LF]> 3c54093a66f94103af3594c3851f070a
[LF]> 
[LF]> This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
[LF]> 
[LF]> *************************************************************
[LF]> *************************************************************
[LF]> *************************************************************

2026-04-12 13:46:46.027+0000 [id=65]    INFO    jenkins.InitReactorRunner$1#onAttained: Completed initialization
2026-04-12 13:46:46.042+0000 [id=42]    INFO    hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running
2026-04-12 13:46:47.011+0000 [id=86]    INFO    h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
2026-04-12 13:46:47.011+0000 [id=86]    INFO    hudson.util.Retrier#start: Performed the action check updates server successfully at the attempt #1

Install plugins Install SSH server plugin Access Jenkins via ssh




dave@fedora:/git/devops-docker$ ssh -p 2222 dave@localhost help
  add-job-to-view
    Adds jobs to view.
  build
    Builds a job, and optionally waits until its completion.
  cancel-quiet-down
    Cancel the effect of the "quiet-down" command.
  clear-queue
    Clears the build queue.
  connect-node
    Reconnect to a node(s)
  console
    Retrieves console output of a build.
  copy-job
    Copies a job.
  create-credentials-by-xml
    Create Credential by XML
  create-credentials-domain-by-xml
    Create Credentials Domain by XML
  create-job
    Creates a new job by reading stdin as a configuration XML file.
  create-node
    Creates a new node by reading stdin as a XML configuration.
  create-view
    Creates a new view by reading stdin as a XML configuration.
  declarative-linter
    Validate a Jenkinsfile containing a Declarative Pipeline
  delete-builds
    Deletes build record(s).
  delete-credentials
    Delete a Credential
  delete-credentials-domain
    Delete a Credentials Domain
  delete-job
    Deletes job(s).
  delete-node
    Deletes node(s)
  delete-view
    Deletes view(s).
  disable-job
    Disables a job.
  disable-plugin
    Disable one or more installed plugins.
  disconnect-node
    Disconnects from a node.
  enable-job
    Enables a job.
  enable-plugin
    Enables one or more installed plugins transitively.
  get-credentials-as-xml
    Get a Credentials as XML (secrets redacted)
  get-credentials-domain-as-xml
    Get a Credentials Domain as XML
  get-gradle
    List available gradle installations
  get-job
    Dumps the job definition XML to stdout.
  get-node
    Dumps the node definition XML to stdout.
  get-view
    Dumps the view definition XML to stdout.
  groovy
    Executes the specified Groovy script. 
  groovysh
    Runs an interactive groovy shell.
  help
    Lists all the available commands or a detailed description of single command.
  import-credentials-as-xml
    Import credentials as XML. The output of "list-credentials-as-xml" can be used as input here as is, the only needed change is to set the actual Secrets which are redacted in the output.
  install-plugin
    Installs a plugin either from a file, an URL, or from update center. 
  keep-build
    Mark the build to keep the build forever.
  list-changes
    Dumps the changelog for the specified build(s).
  list-credentials
    Lists the Credentials in a specific Store
  list-credentials-as-xml
    Export credentials as XML. The output of this command can be used as input for "import-credentials-as-xml" as is, the only needed change is to set the actual Secrets which are redacted in the output.
  list-credentials-context-resolvers
    List Credentials Context Resolvers
  list-credentials-providers
    List Credentials Providers
  list-jobs
    Lists all jobs in a specific view or item group.
  list-plugins
    Outputs a list of installed plugins.
  mail
    Reads stdin and sends that out as an e-mail.
  offline-node
    Stop using a node for performing builds temporarily, until the next "online-node" command.
  online-node
    Resume using a node for performing builds, to cancel out the earlier "offline-node" command.
  quiet-down
    Quiet down Jenkins, in preparation for a restart. Don’t start any builds.
  reload-configuration
    Discard all the loaded data in memory and reload everything from file system. Useful when you modified config files directly on disk.
  reload-job
    Reload job(s)
  remove-job-from-view
    Removes jobs from view.
  replay-pipeline
    Replay a Pipeline build with edited script taken from standard input
  restart
    Restart Jenkins.
  restart-from-stage
    Restart a completed Declarative Pipeline build from a given stage.
  safe-restart
    Safe Restart Jenkins. Don’t start any builds.
  safe-shutdown
    Puts Jenkins into the quiet mode, wait for existing builds to be completed, and then shut down Jenkins.
  session-id
    Outputs the session ID, which changes every time Jenkins restarts.
  set-build-description
    Sets the description of a build.
  set-build-display-name
    Sets the displayName of a build.
  shutdown
    Immediately shuts down Jenkins server.
  stop-builds
    Stop all running builds for job(s)
  update-credentials-by-xml
    Update Credentials by XML
  update-credentials-domain-by-xml
    Update Credentials Domain by XML
  update-job
    Updates the job definition XML from stdin. The opposite of the get-job command.
  update-node
    Updates the node definition XML from stdin. The opposite of the get-node command.
  update-view
    Updates the view definition XML from stdin. The opposite of the get-view command.
  version
    Outputs the current version.
  wait-node-offline
    Wait for a node to become offline.
  wait-node-online
    Wait for a node to become online.
  who-am-i
    Reports your credential and permissions.
dave@fedora:/git/devops-docker$ 


Run job via ssh 




Trigger a build and follow the logs (Best for Dev):
ssh -p 2222 my_jenkins_user@localhost build "Your-Job-Name" -s -v

Thursday, December 31, 2020

Call another job in Jenkins declarative pipeline with parameters

 HOWTO

 

Parameters on the pipeline job

pipeline {
    agent any
    parameters {
        string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')

        text(name: 'BIOGRAPHY', defaultValue: '', description: 'Enter some information about the person')

        booleanParam(name: 'TOGGLE', defaultValue: true, description: 'Toggle this value')

        choice(name: 'CHOICE', choices: ['One', 'Two', 'Three'], description: 'Pick something')

        password(name: 'PASSWORD', defaultValue: 'SECRET', description: 'Enter a password')
    }
    stages {
        stage('Example') {
            steps {
                echo "Hello ${params.PERSON}"

                echo "Biography: ${params.BIOGRAPHY}"

                echo "Toggle: ${params.TOGGLE}"

                echo "Choice: ${params.CHOICE}"

                echo "Password: ${params.PASSWORD}"
            }
        }
    }
}

 

Called job


pipeline {
    agent { 
       label 'dave_node'
    }
    parameters {
        string(name: 'branch', defaultValue: 'main', description: 'Some branch')
    }
    stages {
        stage('CalledJob') {
        
            steps {
            
                 echo "Build CalledJob branch ${params.branch}"  
                 
                 script {         
                     params.each {param ->
                       println "${param.key} -> ${param.value} "
                     }
                 }
                         
            
                git url: 'https://github.com/dveselka/calledjob/', credentialsId: 'daveCredentials', branch: "${params.branch}"     
            }
        }
    }
}


Calling job

   
       stage('BuildOtherJob') {
            steps {   
            
            echo "Call other job job"        
                script {           
                      build job: 'jobtocall', parameters: [
                             string(name: 'branch', value: "some_branch")
                        ]
                }
            }
       }    


Dynamic agent

pipeline {
    agent { 
       label params.agent == null || params.agent.isEmpty() ? "default-agent" : params.agent
    }

Sunday, December 27, 2020

Deploy JBoss Wildfly Java EE app with Maven using Jenkins pipeline and Docker

 HOWTO

 

GitHub projects


Pipeline file https://github.com/dveselka/java-ee-8/blob/main/java-ee8-minimal/Jenkinsfile

Add jenkins user into docker group

sudo usermod -aG docker jenkins
sudo systemctl restart jenkins

Checkout app from GitHub

        stage('Checkout') {
          git url: 'https://github.com/dveselka/java-ee-8/', credentialsId: 'dave-devops', branch: 'main'
        }

 

Build application using Maven

        stage('Build') {
          
          dir('java-ee8-minimal'){
             withMaven(maven:'Maven'
             ) {
                sh 'pwd'
                sh 'env'
                sh 'mvn clean package'
            
                def pom = readMavenPom file:'pom.xml'
                print pom.version
                env.version = pom.version
             }
          }
        }

 

Build Docker image

https://www.jenkins.io/doc/book/pipeline/docker/
        stage("BuildDockerImage"){
          dir('java-ee8-minimal'){
            def customImage = docker.build("my-image:${env.BUILD_ID}")
          }
        }
Jenkins log - Docker image build
[Pipeline] { (Image)
[Pipeline] dir
Running in /var/lib/jenkins/workspace/java-ee-8/java-ee8-minimal
[Pipeline] {
[Pipeline] isUnix
[Pipeline] sh
+ docker build -t com.dave/java-ee8-minimal:4 .
Sending build context to Docker daemon  46.59kB

Step 1/4 : FROM jboss/wildfly
 ---> 8d9094a2468d
Step 2/4 : RUN /opt/jboss/wildfly/bin/add-user.sh admin Admin#123 --silent
 ---> Using cache
 ---> 8b8272a09327
Step 3/4 : COPY ./target/java-ee8-minimal.war /opt/jboss/wildfly/standalone/deployments/
 ---> 229ba08da529
Step 4/4 : CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]
 ---> Running in fdea8bab71ee
Removing intermediate container fdea8bab71ee
 ---> c165d87af41e
Successfully built c165d87af41e
Successfully tagged com.dave/java-ee8-minimal:4

 

Push Docker image to repository (optional)

 

Run container

        stage ('Run') {
          dir('java-ee8-minimal'){
            docker.image("com.dave/java-ee8-minimal:${env.BUILD_ID}").run('-it --name java-ee8-minimal com.dave/java-ee8-minimal')
          }
        }

 

Install Jenkins Docker plugin to remove this error

groovy.lang.MissingPropertyException: No such property: docker for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:270)

 
Jenkins log - run Docker container

[Pipeline] { (Run)
[Pipeline] dir
Running in /var/lib/jenkins/workspace/java-ee-8/java-ee8-minimal
[Pipeline] {
[Pipeline] isUnix
[Pipeline] sh
+ docker run -d -it --name java-ee8-minimal com.dave/java-ee8-minimal:6
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
Docker process
docker ps -a
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS              PORTS               NAMES
0eb3d2588c6b        com.dave/java-ee8-minimal:6   "/opt/jboss/wildfly/…"   2 minutes ago       Up 2 minutes        8080/tcp            java-ee8-minimal

Monday, November 30, 2020

Configure Jenkins agent using declarative pipeline

HOWTO

Sample projects

 

Configure Jenkins agent

agent

    The agent section specifies where the entire Pipeline, or a specific stage, will execute in the Jenkins environment depending on where the agent section is placed. The section must be defined at the top-level inside the pipeline block, but stage-level usage is optional.

 

label 
  
   Execute the Pipeline, or stage, on an agent available in the Jenkins environment with the provided label. For example: agent { label 'my-defined-label' }

 

node

agent { node { label 'labelName' } } behaves the same as agent { label 'labelName' }, but node allows for additional options (such as customWorkspace).

 

Multiple agents

pipeline {
    agent none
    stages {
        stage('Build') {
            agent any
            steps {
                checkout scm
                sh 'make'
                stash includes: '**/target/*.jar', name: 'app' 
            }
        }
        stage('Test on Linux') {
            agent { 
                label 'linux'
            }
            steps {
                unstash 'app' 
                sh 'make check'
            }
            post {
                always {
                    junit '**/target/*.xml'
                }
            }
        }
        stage('Test on Windows') {
            agent {
                label 'windows'
            }
            steps {
                unstash 'app'
                bat 'make check' 
            }
            post {
                always {
                    junit '**/target/*.xml'
                }
            }
        }
    }
} 
Configure GitHub credentials for Jenkins

Configure pipeline 

GitHub credentials must be username/password ( use GH token) 

https://stackoverflow.com/questions/38461705/checkout-jenkins-pipeline-git-scm-with-credentials?rq=1

If you're using the ssh url then your credentials must be username + private key. If you're using the https clone url instead of the ssh one, then your credentials should be username + password.

 To change working dir use dir ('somedir'){ ... }

https://github.com/dveselka/weblogic/blob/master/Jenkinsfile  

node {

        stage('Checkout') {
          git url: 'https://github.com/dveselka/weblogic/', credentialsId: 'dave-devops', branch: 'weblogic-14.1.1'
        }

        stage('Build') {
            dir ('dave-basic-webapp-ejb-project') {
                withMaven(maven:'local') {
                   sh 'mvn clean package'

                   def pom = readMavenPom file:'pom.xml'
                   print pom.version
                   env.version = pom.version
                }
            }     
        }

}

Install Maven pipeline plugin

https://www.jenkins.io/doc/pipeline/steps/pipeline-maven/

https://plugins.jenkins.io/pipeline-maven/

Install  Pipeline utility steps plugin

https://plugins.jenkins.io/pipeline-utility-steps/

 

Configure Maven 

dave@dave ~]$ which mvn
/opt/maven/bin/mvn
[dave@dave ~]$ mvn --version
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T17:06:16+02:00)
Maven home: /opt/maven
Java version: 11.0.9, vendor: Oracle Corporation, runtime: /usr/java/jdk-11.0.9
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.9.15-100.fc32.x86_64", arch: "amd64", family: "unix"

https://docs.oracle.com/en/middleware/fusion-middleware/weblogic-server/12.2.1.4/wlprg/maven.html#GUID-C6FC7582-2D1C-4EA5-B000-71AE9A2F2B05


 Configure Oracle Maven repository for Weblogic


[dave@dave 14.1.1]$ cd /app/weblogic/oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/14.1.1/^C
[dave@dave 14.1.1]$ mvn install:install-file -DpomFile=oracle-maven-sync-14.1.1.pom -Dfile=oracle-maven-sync-14.1.1.jar
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
[INFO] Installing /app/weblogic/oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/14.1.1/oracle-maven-sync-14.1.1.jar to /home/dave/.m2/repository/com/oracle/maven/oracle-maven-sync/14.1.1-0-0/oracle-maven-sync-14.1.1-0-0.jar
[INFO] Installing /app/weblogic/oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/14.1.1/oracle-maven-sync-14.1.1.pom to /home/dave/.m2/repository/com/oracle/maven/oracle-maven-sync/14.1.1-0-0/oracle-maven-sync-14.1.1-0-0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

Install Oracle artifacts into local repo
[dave@dave 14.1.1]$ mvn com.oracle.maven:oracle-maven-sync:push -DoracleHome=/app/weblogic

 

Build pipeline 

 

Started by user DaVe
Obtained Jenkinsfile from git https://github.com/dveselka/weblogic/
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/weblogic-pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] git
The recommended git tool is: NONE
using credential dave-devops
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/dveselka/weblogic/ # timeout=10
Fetching upstream changes from https://github.com/dveselka/weblogic/
 > git --version # timeout=10
 > git --version # 'git version 2.26.2'
using GIT_ASKPASS to set credentials dave-devops
 > git fetch --tags --force --progress -- https://github.com/dveselka/weblogic/ +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/weblogic-14.1.1^{commit} # timeout=10
Checking out Revision d880e4d74b8302545401074d68fd449115fdca1b (refs/remotes/origin/weblogic-14.1.1)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f d880e4d74b8302545401074d68fd449115fdca1b # timeout=10
 > git branch -a -v --no-abbrev # timeout=10
 > git branch -D weblogic-14.1.1 # timeout=10
 > git checkout -b weblogic-14.1.1 d880e4d74b8302545401074d68fd449115fdca1b # timeout=10
Commit message: "Merge pull request #2 from dveselka/master"
 > git rev-list --no-walk 7fe92410b7aab93803b8dbd39200a48c23331709 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] dir
Running in /var/lib/jenkins/workspace/weblogic-pipeline/dave-basic-webapp-ejb-project
[Pipeline] {
[Pipeline] withMaven
[withMaven] Options: []
[withMaven] Available options: 
[withMaven] using JDK installation provided by the build agent
[withMaven] using Maven installation 'local'
[Pipeline] {
[Pipeline] sh
+ mvn clean package
----- withMaven Wrapper script -----
Picked up JAVA_TOOL_OPTIONS: -Dmaven.ext.class.path="/var/lib/jenkins/workspace/weblogic-pipeline/dave-basic-webapp-ejb-project@tmp/withMaven8d13bb8c/pipeline-maven-spy.jar" -Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder="/var/lib/jenkins/workspace/weblogic-pipeline/dave-basic-webapp-ejb-project@tmp/withMaven8d13bb8c" 
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T17:06:16+02:00)
Maven home: /opt/maven
Java version: 11.0.9, vendor: Oracle Corporation, runtime: /usr/java/jdk-11.0.9
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.9.15-100.fc32.x86_64", arch: "amd64", family: "unix"
[INFO] [jenkins-event-spy] Generate /var/lib/jenkins/workspace/weblogic-pipeline/dave-basic-webapp-ejb-project@tmp/withMaven8d13bb8c/maven-spy-20201227-095826-57316330863830296583212.log.tmp ...
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------< dave:dave-basic-webapp-ejb-project >-----------------
[INFO] Building basicWebappEjb 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ dave-basic-webapp-ejb-project ---
[INFO] Deleting /var/lib/jenkins/workspace/weblogic-pipeline/dave-basic-webapp-ejb-project/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dave-basic-webapp-ejb-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ dave-basic-webapp-ejb-project ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 6 source files to /var/lib/jenkins/workspace/weblogic-pipeline/dave-basic-webapp-ejb-project/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ dave-basic-webapp-ejb-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/weblogic-pipeline/dave-basic-webapp-ejb-project/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ dave-basic-webapp-ejb-project ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ dave-basic-webapp-ejb-project ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ dave-basic-webapp-ejb-project ---
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/var/lib/jenkins/.m2/repository/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar) to field java.util.Properties.defaults
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
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
[INFO] Packaging webapp
[INFO] Assembling webapp [dave-basic-webapp-ejb-project] in [/var/lib/jenkins/workspace/weblogic-pipeline/dave-basic-webapp-ejb-project/target/basicWebappEjb]
[INFO] Processing war project
[INFO] Copying webapp resources [/var/lib/jenkins/workspace/weblogic-pipeline/dave-basic-webapp-ejb-project/src/main/webapp]

[INFO] Webapp assembled in [33 msecs]
[INFO] Building war: /var/lib/jenkins/workspace/weblogic-pipeline/dave-basic-webapp-ejb-project/target/basicWebappEjb.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.763 s
[INFO] Finished at: 2020-12-27T09:58:29+01:00
[INFO] ------------------------------------------------------------------------
[INFO] [jenkins-event-spy] Generated /var/lib/jenkins/workspace/weblogic-pipeline/dave-basic-webapp-ejb-project@tmp/withMaven8d13bb8c/maven-spy-20201227-095826-57316330863830296583212.log
[Pipeline] readMavenPom
[Pipeline] echo
1.0-SNAPSHOT
[Pipeline] }
[withMaven] artifactsPublisher - Archive artifact pom.xml under dave/dave-basic-webapp-ejb-project/1.0-SNAPSHOT/dave-basic-webapp-ejb-project-1.0-SNAPSHOT.pom
[withMaven] artifactsPublisher - Archive artifact target/basicWebappEjb.war under dave/dave-basic-webapp-ejb-project/1.0-SNAPSHOT/dave-basic-webapp-ejb-project-1.0-SNAPSHOT.war
[withMaven] junitPublisher - Archive test results for Maven artifact dave:dave-basic-webapp-ejb-project:war:1.0-SNAPSHOT generated by maven-surefire-plugin:test (default-test): target/surefire-reports/*.xml
[withMaven] junitPublisher - Jenkins JUnit Attachments Plugin not found, can't publish test attachments.Recording test results
None of the test reports contained any result
[withMaven] Jenkins Task Scanner Plugin not found, don't display results of source code scanning for 'TODO' and 'FIXME' in pipeline screen.
[withMaven] Publishers: Pipeline Graph Publisher: 3 ms, Generated Artifacts Publisher: 17 ms, Junit Publisher: 31 ms
[Pipeline] // withMaven
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

 

Saturday, November 28, 2020

Install Jenkins via Ansible

HOWTO 


  • Install Jenkins using Galaxy role  https://training.galaxyproject.org/training-material/topics/admin/tutorials/jenkins/tutorial.html



Clone repository with playbook

https://github.com/dveselka/devops-ansible/tree/master/jenkins

[dave@dave ~]$ git clone https://github.com/dveselka/devops-ansible

Install Ansible Galaxy roles
[dave@dave ~]$ cd devops-ansible/
[dave@dave devops-ansible]$ cd jenkins/
[dave@dave jenkins]$ ls
create_jenkins.yml  dev_vars.yml  README.md  requirements.yml
[dave@dave jenkins]$ ansible-galaxy install -p roles -r requirements.yml
- downloading role 'java', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-java/archive/1.10.0.tar.gz
- extracting geerlingguy.java to /home/dave/devops-ansible/jenkins/roles/geerlingguy.java
- geerlingguy.java (1.10.0) was installed successfully
- downloading role 'jenkins', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-jenkins/archive/4.3.0.tar.gz
- extracting geerlingguy.jenkins to /home/dave/devops-ansible/jenkins/roles/geerlingguy.jenkins
- geerlingguy.jenkins (4.3.0) was installed successfully


Check Java version
[dave@dave jenkins]$ java -version
java version "11.0.9" 2020-10-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.9+7-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.9+7-LTS, mixed mode)



Run Ansible playbook
[dave@dave jenkins]$ ansible-playbook -K  create_jenkins.yml 
BECOME password: 
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Install Jenkins on localhost] *****************************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.java : Include OS-specific variables for Fedora or FreeBSD.] **********************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.java : Include version-specific variables for CentOS/RHEL.] ***********************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.java : Include version-specific variables for Ubuntu.] ****************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.java : Include version-specific variables for Debian.] ****************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.java : Define java_packages.] *****************************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.java : include_tasks] *************************************************************************************************************************************************************************
included: /home/dave/devops-ansible/jenkins/roles/geerlingguy.java/tasks/setup-RedHat.yml for localhost

TASK [geerlingguy.java : Ensure Java is installed.] *************************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.java : include_tasks] *************************************************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.java : include_tasks] *************************************************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.java : Set JAVA_HOME if configured.] **********************************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Include OS-Specific variables] ******************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Define jenkins_repo_url] ************************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Define jenkins_repo_key_url] ********************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Define jenkins_pkg_url] *************************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : include_tasks] **********************************************************************************************************************************************************************
included: /home/dave/devops-ansible/jenkins/roles/geerlingguy.jenkins/tasks/setup-RedHat.yml for localhost

TASK [geerlingguy.jenkins : Ensure dependencies are installed.] *************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Ensure Jenkins repo is installed.] **************************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Add Jenkins repo GPG key.] **********************************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Download specific Jenkins version.] *************************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.jenkins : Check if we downloaded a specific version of Jenkins.] ******************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.jenkins : Install our specific version of Jenkins.] *******************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.jenkins : Ensure Jenkins is installed.] *******************************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : include_tasks] **********************************************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.jenkins : include_tasks] **********************************************************************************************************************************************************************
included: /home/dave/devops-ansible/jenkins/roles/geerlingguy.jenkins/tasks/settings.yml for localhost

TASK [geerlingguy.jenkins : Check if jenkins_init_file exists.] *************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Ensure jenkins_init_file exists.] ***************************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.jenkins : Modify variables in init file.] *****************************************************************************************************************************************************
changed: [localhost] => (item={'option': 'JENKINS_ARGS', 'value': '--prefix='})
changed: [localhost] => (item={'option': 'JENKINS_JAVA_OPTIONS', 'value': '-Xmx4096M'})

TASK [geerlingguy.jenkins : Ensure jenkins_home /var/lib/jenkins exists.] ***************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Set the Jenkins home directory.] ****************************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Immediately restart Jenkins on init config changes.] ********************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Set HTTP port in Jenkins config.] ***************************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Create custom init scripts directory.] **********************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Configure proxy config for Jenkins] *************************************************************************************************************************************************
skipping: [localhost]

RUNNING HANDLER [geerlingguy.jenkins : configure default users] *************************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Immediately restart Jenkins on http or user changes.] *******************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Ensure Jenkins is started and runs on startup.] *************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Wait for Jenkins to start up before proceeding.] ************************************************************************************************************************************
FAILED - RETRYING: Wait for Jenkins to start up before proceeding. (60 retries left).
FAILED - RETRYING: Wait for Jenkins to start up before proceeding. (59 retries left).
FAILED - RETRYING: Wait for Jenkins to start up before proceeding. (58 retries left).
ok: [localhost]

TASK [geerlingguy.jenkins : Get the jenkins-cli jarfile from the Jenkins server.] *******************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Remove Jenkins security init scripts after first startup.] **************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : include_tasks] **********************************************************************************************************************************************************************
included: /home/dave/devops-ansible/jenkins/roles/geerlingguy.jenkins/tasks/plugins.yml for localhost

TASK [geerlingguy.jenkins : Get Jenkins admin password from file.] **********************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.jenkins : Set Jenkins admin password fact.] ***************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Create Jenkins updates directory.] **************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Download current plugin updates from Jenkins update site.] **************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Remove first and last line from json file.] *****************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Install Jenkins plugins using password.] ********************************************************************************************************************************************

PLAY RECAP ******************************************************************************************************************************************************************************************************
localhost                  : ok=34   changed=13   unreachable=0    failed=0    skipped=13   rescued=0    ignored=0   


Configure nodes 

https://www.howtoforge.com/tutorial/ubuntu-jenkins-master-slave/



Thursday, December 26, 2019

Continuous Deployment (CD) with Jenkins and Kubernetes on Google Cloud

Jenkins on Kubernetes Engine

https://cloud.google.com/solutions/jenkins-on-kubernetes-engine

https://cloud.google.com/solutions/jenkins-on-kubernetes-engine-tutorial

Provision a Jenkins environment on a Kubernetes Engine Cluster, using the Helm Package Manager.
Google Kubernetes Engine (GKE) is the hosted version of Kubernetes on Google Cloud Platform (GCP).

Create k8s cluster

gcloud container clusters create jenkins-cd \

  --num-nodes 2 \

  --machine-type n1-standard-2 \

  --cluster-version 1.13 \

  --service-account "jenkins-sa@$GOOGLE_CLOUD_PROJECT.iam.gserviceaccount.com"


 Jenkins Kubernetes plugin
https://wiki.jenkins-ci.org/display/JENKINS/Kubernetes+Plugin 

Scale

kubectl --namespace=production scale deployment gceme-frontend-production --replicas=4


Port forward

export DEV_POD_NAME=$(kubectl get pods -n new-feature -l "app=gceme,env=dev,role=frontend" -o jsonpath="{.items[0].metadata.name}")

kubectl port-forward -n new-feature $DEV_POD_NAME 8001:80 >> /dev/null &




export FRONTEND_SERVICE_IP=$(kubectl get -o jsonpath="{.status.loadBalancer.ingress[0].ip}" --namespace=production services gceme-frontend)


while true; do curl http://$FRONTEND_SERVICE_IP/version; sleep 1; done