Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy Jenkins pipes

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about how to deploy the Jenkins pipeline. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Jenkins

Jenkins is an open source continuous integration tool written in Java. After a dispute with Oracle, the project is replicated from the Hudson project.

Jenkins provides continuous integration services for software development. It runs in a Servlet container (for example, Apache Tomcat). It supports software configuration management (SCM) tools (including AccuRev SCM, CVS, Subversion, Git, Perforce, Clearcase, and RTC) to execute Apache Ant and Apache Maven-based projects, as well as arbitrary Shell scripts and Windows batch commands. The main developer of Jenkins is Kensuke Kawaguchi. Jenkins is free software released under the MIT license.

The build can be triggered by a variety of means. For example, it can be triggered when submitted to a version control system, can be scheduled through a mechanism like Cron, or can be requested through a specific URL when other builds have been completed.

Create Pipeline

After the basic environment is set up, let's configure a workflow to experience it for ourselves.

The running behavior of workflow known as pipeline,pipeline in Jenkins is defined by the user. The defined content is stored in a Jenkinsfile file and stored in the root directory of the git repository. The general process is as follows

The user submits the code to git

Jenkins pulls the latest code from git

Read the Jenkinsfile file in the root directory and perform the tasks defined in the file in turn

Here are the specific configuration steps

Write Jenkinsfilepipeline {agent {label 'master' / * execution node * /} stages {stage (' Build') {steps {echo 'Building'}} stage (' Test') {steps {echo 'Testing'} } stage ('Deploy-Staging') {steps {sh'. / deploy staging' sh'. / run-smoke-tests'}} stage ('Sanity check') {steps {input "Does the staging environment look ok?"}} Stage ('Deploy-Production') {steps {echo'. / deploy production'} post {always {echo 'One way or another I have finished' deleteDir () / * clean up our workspace * /} success {echo'I succeeded'} unstable {echo'I am unstable: /'} failure {echo'I failed: ('} changed {echo 'Things were different before...'})

The above is a basic Jenkinsfile template with the following key concepts

Agent-specify the machine on which to perform the task. Remember the Label entered when configuring Node above, and if the two label match, execute it in that Node.

Stage-the big steps that make up the workflow, which are serial, such as build,test,deploy, etc.

Steps-describes the small steps in stage. Steps in the same stage can be in parallel.

Sh-execute the shell command

Input-you need to manually click OK before Pipeline will enter the follow-up step, which is often used in the deployment process, because most of the time, the deployment requires artificial confirmation.

After all the pipeline execution of the post- is completed, it will enter the post link, which generally does some cleaning work and can also judge the execution status of the pipeline.

After knowing this, you will find that it is easy to write a Jenkinsfile. OK, now to test the pipeline function, replace the sh in the above code with echo, copy it to your Jenkinsfile, and store it in the root directory of the git repository

Create pipeline

Go back to the Jenkins web page and add pipeline

If you want to execute the pipeline automatically every time you git commit, there are two ways. One is to have Jenkins poll the git and check the git repository every minute for updates, as follows

Another way is to use the hook provided by git, the principle of this method is that once git is submitted, it will trigger the script in hook and let the script send instructions to Jenkins to execute pipeline. This way is more elegant, but there is a little more work to be done accordingly. This method will not be demonstrated here. Interested students can study it by themselves.

Finally, we need to set the address of git, where the credit setting is the same as the Master to Node credit setting mentioned above.

After setting up, once your git warehouse receives a new submission, the pipeline will be triggered. The following figure shows the running status of the above Jenkinsfile example. You can see whether you need to manually trigger whether to perform subsequent operations when running to the Sanity check step.

Other

Project address: https://github.com/changdaye/jenkins-docker-demo/

Step graphical plug-in introduction: https://wiki.jenkins.io/display/JENKINS/Pipeline+Stage+View+Plugin

The above is the editor for you to share how to deploy the Jenkins pipeline, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report