jenkins install and build demo

Posted May 27, 20203 min read

1. Installation

  • Download link

  • Installation

      nohup java -DJENKINS_HOME =/home/jenkins/root -jar home/jenkins/jenkins.war --httpPort = 8888 &
  • Visit

        http://192.168.1.102:8888
        //If it fails, you can turn off the firewall
  • Modify the official warehouse address

        sed -i "s/https:\/\/updates.jenkins.io \ /update-center.json/https:\/\/mirrors.tuna.tsinghua.edu.cn \/jenkins \/updates \/update- center.json/g "/home/jenkins/root/hudson.model.UpdateCenter.xml
  • Stop Jenkins

  • Modify the default Jenkins plugin source and connection detection location

      sed -i 's/http:\/\/updates.jenkins-ci.org \/download/https:\/\/mirrors.tuna.tsinghua.edu.cn \/jenkins/g'/home/jenkins/root /updates/default.json
    
      sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' /home/jenkins/root/updates/default.json
  • Restart Jenkins

  • View administrator password

      cat ./root/secrets/initialAdminPassword
    
      447b5e78c2f1428dbbd9ab571209b75d
  • Click Continue to enter Jenkins
    image.png

  • Install recommended plugins
    image.png

  • Partially failed to install the plugin, click continue
    image.png

  • Create administrator user
    image.png

  • Configure Jenkins url and start using Jenkins
    image.png

  • Restart Jenkins and log in with admin/password
    image.png

  • Click automatic upgrade to upgrade Jenkins
    image.png

  • auto update
    image.png

  • Restart
    image.png

  • Restart
    image.png

3. Create a statement pipeline demo

  • New item
    image.png

  • Enter the task name, select the pipeline, check Allow parameterization, and enter the parameters
    image.png

  • Modify the script
    image.png
    script

          pipeline {
            agent any;
            environment {//Environmental variables
                GITURL = "https://github.com/xiayu/";
            }
            stages {
                stage('Get git code') {
                    steps {
                        sh 'echo "$GITURL $BRANCH"'
                    }
                }
           }
           post {//Post operation after construction is completed
                aborted {//execute if the build is interrupted
                    echo 'Build was aborted!'
                }
                success {//Build successfully executed
                    echo 'Build successful!'
                }
               failure {//Build failed execution
                   echo 'Build failed!'
               }
            }
        }
  • Parameter construction
    image.png

  • Start building
    image.png

  • Build result
    image.png

Reference: https://www.cnblogs.com/hellxz/p/jenkins_pipeline_helloworld.html
https://www.cnblogs.com/hellxz/p/install_jenkins.html