在对jenkins进行初始化安装时,默认已经安装了jenkins的相关插件,以下图所示:node
新建任务:git
编写pipeline脚本:服务器
咱们能够借助流水线语法去作。app
test流水线脚本:maven
node { def mvnHome stage('git checkout') { // for display purposes checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'git@172.16.1.3:/home/git/repos/app.git']]]) } stage('maven Build') { echo "maven build........." } stage('deploy') { echo "deploy..........." } stage('test') { echo "test..........." } }
构建测试:测试
能够去服务器上验证一下(git checkout)刚才拉取下来的代码:ui
补充:url
咱们也能够从咱们的代码版本管理仓库中读取pipeline脚本(至关于将pipeline脚本放在仓库中)咱们能够选择git。spa
首先咱们须要将咱们的pipeline脚本提交到咱们新建的git仓库中插件
步骤再此忽略。
jenkins项目中须要进行以下配置:
其中脚本路径的配置,必定要和版本仓库中的路径相一致。
以后咱们若是要更改步骤,不须要再更改jenkins的步骤,直接更改文件便可。
补充:
此外咱们以前的测试一直是在master上构建的,咱们还能够经过在jenkinsfile中指定节点在相应节点去构建
具体在jenkinsfile的node后进行指定:
以下图所示:
格式为:node ("节点名称")