What is Jenkins?

Jenkins is an open source, user-friendly continuous integration (CI) tool that integrates Git plug-ins and originated in Hudson. Mainly used for continuous, automated build projects.

In a word, Jenkins

Jenkins can automatically pull github code for us, help us compile, package, execute, deploy automation tools.

Knowledge of the GET

CD, CI concepts

CI concept:

Continuous integration is a software development practice in which team development members frequently integrate their work, meaning that by each member integrating at least once a day, multiple integrations may occur per day. Each integration is verified by an automated build (including compilation, release, and automated testing) to catch integration errors early

CD concept:

Continuous Deployment is the rapid delivery of high-quality products through an automated build, test, and deployment cycle.

Pipeline concept

Jenkins is basically an automation engine that supports multiple automation modes. Pipeline has added a powerful set of automation tools to Jenkins to support use cases from simple connection integration to full continuous delivery pipelines. It can be used to implement more loaded modeling scenarios. Pipeline currently supports Java/Node.js/Javascript/Ruby/Python/PHP

How to implement WebPack packaging

  1. Edit the Jenkins Job configuration item

  1. Locate the Pipeline configuration and selectPipeline scriptPost write script

node {
    def folderName = "${projectName}-${version}"
    sh "rm -rf ${folderName}"
    sh "mkdir -p ${folderName}"

    stage('Project get Code ') {
        dir("${folderName}")
        {
            checkout scm
        }

        echo "Pull code successful"
    }

    stage('Main Project Build') {
        
        dir("${folderName}")
        {
            sh "sed -i 's/{version}/${version}/g' package.json"
            sh "cp ${projectName}/mainProjectBuild.sh ./"
            sh "sed -i 's/{version}/${version}/g' mainProjectBuild.sh"
            sh "sh mainProjectBuild.sh"
			
            echo "Compile & package complete"
        }
    }
  
    stage('Results') {
        echo "Successful release"}}Copy the code

Pipeline grammarPay attention to

  • Scripted Pipelines execute sequentially from the top
  • node {}The outermost layer must be the Node node, declaring the workspace
  • def folderName = "${projectName}-${version}"Declare local variables
  • sh "rm -rf ${folderName}"Run the shell commandrm -rf xx. It will only continue if the command returns a zero exit code, and any non-zero exit code the entire Pipeline will be judged as a deployment failure.
  • ${folderName}Variables can be retrieved in this shell-like fashion.
  • stage('Project get Code '){}Stage is the syntax for a stage, with the stage name in parentheses. The script starts from Node and works its way down. Encountering a stage is a stage.
  • dir("xx")Change the execution directory.
  • checkout scmIs Jenkins’ fixed access method, which prints Check out from version control
  • Echo "pull code successful"Output text to give current progress information

The attached mainProjectBuild. Sh

npm install
npm run build
zip -r {version}.zip dist
Copy the code