美文网首页
【Jenkins插件】Jenkins pipeline 参数化构

【Jenkins插件】Jenkins pipeline 参数化构

作者: 87d6dc4b11a7 | 来源:发表于2023-02-03 19:23 被阅读0次

在Jenkins页面流水线语法页面,选择input,可以帮助我们生产关于参数使用的流水线脚本。

image.png image.png

示例:

pipeline {
    agent any
    options {
        //丢弃旧的构建,保持构建的最大个数为10
        buildDiscarder logRotator(numToKeepStr: '10')
        //禁止流水线的并发执行,有助于防止共享资源被同时访问
        disableConcurrentBuilds()
        //设置流水线超时时间
        timeout(time: 1, unit: 'HOURS')
    }
    parameters {
        string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')

        text(name: 'BIOGRAPHY', defaultValue: '', description: 'Enter some information about the person')

        booleanParam(name: 'TOGGLE', defaultValue: true, description: 'Toggle this value')

        choice(name: 'CHOICE', choices: ['One', 'Two', 'Three'], description: 'Pick something')

        password(name: 'PASSWORD', defaultValue: 'SECRET', description: 'Enter a password')

        extendedChoice(defaultValue: 'One,Two,Three', value: 'One,Two,Three', description: '', multiSelectDelimiter: ',', name: 'EXTENDEDCHOICE', quoteValue: false, type: 'PT_CHECKBOX', visibleItemCount: 15)
    }
    stages {
        stage('Example') {
            steps {
                echo "Hello ${params.PERSON}"

                echo "Biography: ${params.BIOGRAPHY}"

                echo "Toggle: ${params.TOGGLE}"

                echo "Choice: ${params.CHOICE}"

                echo "Password: ${params.PASSWORD}"

                echo "ExtendedChoice: ${params.EXTENDEDCHOICE}"
            }
        }
    }
}

参考链接:https://www.jenkins.io/doc/book/pipeline/syntax/#parameters
https://plugins.jenkins.io/extended-choice-parameter/
https://github.com/jenkinsci/extended-choice-parameter-plugin

相关文章

网友评论

      本文标题:【Jenkins插件】Jenkins pipeline 参数化构

      本文链接:https://www.haomeiwen.com/subject/pxjnhdtx.html