2

Using Jenkins pipeline we have our own build script. Also all of our projects have a rakefile which is what we use to do a lot of the building steps. Our typical jenkins build executes 3 rake tasks but we do have some exceptions and that has to do when we have a angular website we try to build with it.

I've configured my pipeline like this:

buildGitProject {
    repository='https://anonymous.visualstudio.com/Project/_git/my-csharp-project-with-angular'
    branchName= 'master'
    solutionName='MyCSharpSolution.sln'
    emailTo='[email protected]'
    preRakeCommands=['install_npm_dependencies', 'ng_build']
}

that relies on our build script which is this:

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)
                }
            }
        }
    }
}

which fails in the build stage. 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}"
}

in the jenkins build log it says:

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

I have no idea how or why it is using a string pointer because I thought that plus concated arrays and ArrayList... Plus it is in Jenkins so it is a pain to test.

1
  • fixed it.. silly me. I should have used ArrayList.addAll. Silly C# habbits Commented Aug 2, 2018 at 13:38

2 Answers 2

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

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

output:

[a1, a2, a3, s1, s2, s3, b1, b2, b3]
Sign up to request clarification or add additional context in comments.

1 Comment

i used a slightly different approach but this one would have worked too. Thank you.
2

Another approach:

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

println ([*a,*s,*b])

alternatively

println a + [*s] + b

which should perform better

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.