jenkins - 将数组和 ArrayList 追加到 ArrayList

标签 jenkins groovy jenkins-pipeline

使用 Jenkins 管道,我们有自己的构建脚本。此外,我们所有的项目都有一个 rakefile,我们用它来执行许多构建步骤。我们典型的 jenkins 构建执行 3 个 rake 任务,但我们确实有一些异常(exception),当我们尝试用它构建一个有角度的网站时,就必须这样做。

我已经像这样配置了我的管道:

buildGitProject {
    repository='https://anonymous.visualstudio.com/Project/_git/my-csharp-project-with-angular'
    branchName= 'master'
    solutionName='MyCSharpSolution.sln'
    emailTo='<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="80f3efede5efeee5c0e1efecaee3efed" rel="noreferrer noopener nofollow">[email protected]</a>'
    preRakeCommands=['install_npm_dependencies', 'ng_build']
}

这依赖于我们的构建脚本,如下所示:

def call(body) {
    def args= [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = args
    body()

    def agentName = "windows && ${args.branchName}"
    def remoteConfig = org.pg.RemoteConfigFactory.create(args.repository);

    pipeline {
        agent none
        options {
            buildDiscarder(logRotator(numToKeepStr: org.pg.Settings.BUILDS_TO_KEEP))
            skipStagesAfterUnstable()
            timestamps()
        }
        stages {
            stage("checkout") {
                agent any
                steps {
                    checkoutFromGit(remoteConfig, args.branchName)
                }
            }
            stage('build') {
                agent{node{ label agentName as String}}
                steps {
                    buildSolution(args.solutionName, args.get('preRakeCommands', []), args.get('postRakeCommands', []))
                }
            }
            stage('test') {
                agent{node{ label agentName as String}}
                steps {
                    testSolution(args.solutionName)
                }
            }
        }
    }
}

在构建阶段失败。 buildSolution.groovy

def call(String solutionName, ArrayList preRakeCommands, ArrayList postRakeCommands) {
    unstash 'ws'
    String[] rakeCommands = [
        "build_solution[${solutionName}, Release, Any CPU]",
        "copy_to_deployment_folder",
        "execute_dev_dropkick"
    ]
    String[] combinedRakeCommand = (preRakeCommands.plus(rakeCommands).plus(postRakeCommands)) as String[]
    executeRake( combinedRakeCommand )
    stash name: 'deployment', includes: 'deployment/**/*'
}

executeRake.groovy

def call(String... rakeTasks) {
    def safeRakeTasks = rakeTasks.collect{ "\"$it\"" }.join(' ');
    bat script: "rake ${safeRakeTasks}"
}

在 Jenkins 构建日志中它说:

08:43:09 C:\jenkins_repos\Project\my-csharp-project-with-angular>rake "install_npm_dependencies" "ng_build" "[Ljava.lang.String;@11bd466" 

我不知道它如何或为什么使用字符串指针,因为我认为 plus 连接数组和 ArrayList...加上它是在 Jenkins 中,所以测试起来很痛苦。

最佳答案

List a = ['a1','a2','a3']
String [] s = ['s1','s2','s3']
List b = ['b1','b2','b3']

println a.plus(s as List).plus(b)

输出:

[a1, a2, a3, s1, s2, s3, b1, b2, b3]

关于jenkins - 将数组和 ArrayList 追加到 ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51654561/

相关文章:

jenkins - 使用 groovy 解析 Jenkin 的 shell 脚本中的 JSON 对象

Jenkins Pipeline、下游作业和代理标签

git - Jenkins 在Docker错误:CP命令无法找到目录

Groovy - 覆盖单个实例的 invokeMethod

grails - grails run-app返回 “context initialization failed”的奇怪情况

Groovy 父/子私有(private)字段访问异常与关闭

git - 如果标记为 "Skip default checkout",则 Jenkins 获取变量 GIT_URL 不可用

java - 我启用了 rerunFailingTestsCount Surefire 功能。如何配置 Jenkins CI 以显示丰富的测试数据?

jenkins - 如何在 Gitlab Jenkins 中无需提交即可重建

Jenkins-pipeline 从 groovy 中的属性文件中提取并设置变量