首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在Jenkinsfile中正确传递函数的映射

无法在Jenkinsfile中正确传递函数的映射
EN

Stack Overflow用户
提问于 2020-10-23 21:48:42
回答 1查看 21关注 0票数 0
代码语言:javascript
复制
def parallelIntegrationTests(stages) {
def tests = stages.collectEntries{ stagename, config ->
    config = [solr: true, failonerror: true]
    [(stagename): {
        stage(stagename) {
            node('integration && php7.1') {
                ws('/var/lib/jenkins/shared-workspace/in-integration') {
                    try {
                        if (config.solr) {
                            sh "/usr/bin/ant -buildfile in/build.xml -Dphpunit.integration.group=${stagename} -Dphpunit.integration.failonerror=${config.failonerror} integration"
                        } else {
                            sh "/usr/bin/ant -buildfile in/build.xml integration-functional"
                        }
                    } catch (e) {
                        throw e
                    } 
                }
            }
        }
    }]
}
parallel tests

}

代码语言:javascript
复制
parallelIntegrationTests(
                        [
                                'integration-functional': {solr: false},
                                'security-authentication': {},
                                'api-infra': {},
                                'external-dependencies': {failonerror: false},
                                'registration': {}
                        ]
                )

我正在尝试根据函数中的参数send来处理if else条件。但是,当jenkinsfile运行并调用parallelIntegrationTests时,本地设置的配置参数"config = solr: true,failonerror: true“将覆盖来自调用函数的参数send。我该怎么处理呢?

EN

回答 1

Stack Overflow用户

发布于 2020-10-27 00:39:11

正确的函数是:

代码语言:javascript
复制
def parallelIntegrationTests(stages) {
def tests = stages.collectEntries{ stagename, config ->
config = [solr: true, failonerror: true] + config
[(stagename): {
    stage(stagename) {
        node('integration && php7.1') {
            ws('/var/lib/jenkins/shared-workspace/in-integration') {
                try {
                    if (config.solr) {
                        sh "/usr/bin/ant -buildfile in/build.xml -Dphpunit.integration.group=${stagename} -Dphpunit.integration.failonerror=${config.failonerror} integration"
                    } else {
                        sh "/usr/bin/ant -buildfile in/build.xml integration-functional"
                    }
                } catch (e) {
                    throw e
                } 
            }
        }
    }
}]

}个并行测试

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64501241

复制
相关文章

相似问题

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