Jenkins pipeline 流水线

本文详述了如何在Jenkins上创建Pipeline,实现从GitHub获取源代码、编译和测试的自动化流程。首先登录Jenkins网页配置节点,接着创建Pipeline并指定Jenkinsfile路径。然后在GitHub上创建Jenkinsfile,定义scripted或declarative pipeline的各个阶段。最后,可以通过触发器设置定期构建,并通过Console Output查看构建日志。
摘要由CSDN通过智能技术生成

这篇文章是让读者能快速的建立Jenkins流水线。 流水线能从GitHub 取得source code,编译,测试。而且能在定时启动流水线。

Login to Jenkins webpage. I setup a Jenkins on my local machine, in this case, the url is 0.0.0.0:8080. Go to Manage Jenkins -> Manage Nodes and Clouds
在这里插入图片描述
The node name is “master”.
在这里插入图片描述
In Jenkins , create a new Pipeline. In the pipeline script, choose Pipeline script from SCM and set script path to Jenkinsfile.
在这里插入图片描述
In the github url, create a Jenkinsfile. For scripted pipeline, create the node master. Create three stages.

node (‘master’) {
   stage(‘Source’) {
     git ‘https://github.com/victoryeo/cppcode/'
   } 
   stage(‘Build’) {
     sh ‘make’
   } 
   stage(‘Test’) {
     echo “Test”
     sh ‘./quotient’
   } 
}

In the Jenkins web page, click on the Build now option.
在这里插入图片描述
After build is completed, in the Build History pane, click on number, e.g. #10 to examine the build history.
在这里插入图片描述
Then, click on Console Output to inspect the build log.
在这里插入图片描述
For declarative pipeline, create the stages, three stage, and steps.

pipeline {
 agent any 
 stages {
   stage(‘Source’) {
     steps {    
       git ‘https://github.com/victoryeo/cppcode/'
     }
   } 
   stage(‘Build’) {
     steps {
       sh ‘make clean’
       sh ‘make’
     }
   } 
   stage(‘Test’) {
     steps {
       echo “Test”
       sh ‘./quotient’
     }
   } 
 } 
}

Additionally, in declarative pipeline, we can add triggers to Jenkinsfile to schedule periodic build.

pipeline {
    agent any
    triggers {
        cron('H 9-16/2 * * 1-5') 
# the field follows the syntax of cron (with minor differences).  
# Specifically, each line consists of 5 fields
# MINUTE HOUR DOM MONTH DOW
# eg. once every two hours every weekday
    }
    stages {
        stage('Example') {
            steps {
                echo 'Hello World'
            }
        }
    }
}

The Jenkinsfile and C++ code are available at https://github.com/victoryeo/cppcode/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值