jenkins声明式流水线

2020-09-14  本文已影响0人  快乐的涨姿势

pipeline最简结构

pipeline{
    agent any
    stages{
        stage('build'){
            steps{
                echo "我是一个最简结构,缺一不可"
            }
        }
    }
}

pipeline代码块

image-20190606153031994.png

agent

environment

tools

pipeline{
    agent any
    tools{
        maven 'maven3-6'
    }
    stages{
        stage('build'){
            steps{
                sh 'mvn clean test install'
                echo "tools命令自动安装maven"
            }
        }
    }
}

options

保留历史构建记录的数量
options{
    buildDiscarder(logRotator(numToKeepStr:'10'))
}
指定从版本库中检出源码时的检出目录
不允许并发构建
重试次数
超时
让每个stage都分别运行在一个新的容器中
添加时间戳到控制台输出中
其他,后期完善
pipeline{
    agent any
    options{
        buildDiscarder(logRotator(numToKeepStr:'10'))
    }
    stages{
        stage('build'){
            steps{
                echo "保留最近十次的构建"
            }
        }
    }
}

triggers

cron
// 从周一到周五上午8点开始执行流水线
triggers{
    cron('0 8 * * 1-5')
}
pollSCM
// 每分钟判断一次代码是否有变化
triggers{
    pollSCM('*/1 * * * *')
}
upstream

parameters

参数化pipeline是指可以通过传参来决定pipeline的行为

参数化让写pipeline就像写函数,可重用

上一篇 下一篇

猜你喜欢

热点阅读