首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jenkins管道(声明式或脚本化)是否有可能支持像C中的#include这样的预处理?

Jenkins管道(声明式或脚本化)是否有可能支持像C中的#include这样的预处理?
EN

Stack Overflow用户
提问于 2021-10-31 09:16:28
回答 1查看 65关注 0票数 0

我在同一个视图中有一堆作业,它们使用相同的声明性管道结构,除了以下部分:

代码语言:javascript
复制
parameters {
    string(name: 'total_try_count', defaultValue: '1', description: '總的嘗試次數')
    choice(name: 'intermediate_dir', choices: '/var/lib/jenkins-slave/', description: '在放入 NAS 前保存視頻和字幕的目錄')
    booleanParam(name: 'unplanned_download', defaultValue: false, description: '臨時起意的下載?')
    ...
    ...
    choice(name: 're_pattern', choices: '', description: '正則表達式待匹配模式')
    booleanParam(name: 're_remove_spaces', defaultValue: true, description: '刪除文件名中的空格?')
    string(name: 're_new_pattern_prefix', defaultValue: '', description: '正則表達式新模式前綴')
}

是否可以将参数存储在文本文件中,然后像C/C++中的#include指令那样将它们包含在管道中

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-01 05:11:50

我的Jenkinsfile文件:

代码语言:javascript
复制
#!/usr/bin/env groovy
import hudson.model.*
import hudson.EnvVars

node('whatever') {
    checkout scm
    def options = load 'script.groovy'

    properties([parameters(options.params())])

    println "${params.TEST_PARAM}"

}

我的外部groovy文件script.groovy:

代码语言:javascript
复制
def params() {
    [
            string(defaultValue: 'default', description: '', name: 'TEST_PARAM', trim: true)
    ]
}

return this

输出:

代码语言:javascript
复制
[Pipeline] load
[Pipeline] { (script.groovy)
[Pipeline] }
[Pipeline] // load
[Pipeline] properties
[Pipeline] echo
default
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69785421

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档