You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Sakthivel Subramanian <sa...@gmail.com> on 2017/10/02 03:41:37 UTC

Need help in each loop to run multiple steps

Hi,

I am trying loop through array values using each and wants to run 2 set of
operation but when I add it it throws some closure issue (I m pretty new to
groovy, didn’t get what it meant by). Here is the sample code which I am
trying. Commented two lines are the one which I want to execute before
creating pipelineJob.  Can anyone help with the syntax? Or anyother method
to loop array values and create pipeline job and other script execution.
Please help.



create_job.groovy

=================


def apps = [


   [project:"myproj",repo:"my-test-repo1"],

   [project:"testproj",repo:"my-test-repo2"],

   [project:"myproj",repo:"my-dev-repo"]

]



apps.each {

       app ->


       //mystashurl = 'mybaseurl+scm/'+app.project+'/' + app.repo + '.git'

       //sh("sed -i.bak -e 's#--GIT_URL--#${mystashurl}#' Jenkinsfile")


       pipelineJob('LIB.' + app.repo.replaceAll('-','')) {

       description('Containerized microservice lib config')



       definition {

        cps

        {

            script(readFileFromWorkspace('Jenkinsfile'))

            sandbox()

        }

    }



   }

}




Thanks,

Sakthi

Re: Need help in each loop to run multiple steps

Posted by Paul King <pa...@asert.com.au>.
I haven't look into the jenkins job DSL any time recently. It might pay to
ask questions about that on their community support channels. Otherwise
including the closure stack trace you spoke of might help. Nothing jumps
out at me as wrong in what you have.

Cheers, Paul.

On Mon, Oct 2, 2017 at 1:41 PM, Sakthivel Subramanian <sakthi.99it@gmail.com
> wrote:

> Hi,
>
> I am trying loop through array values using each and wants to run 2 set of
> operation but when I add it it throws some closure issue (I m pretty new to
> groovy, didn’t get what it meant by). Here is the sample code which I am
> trying. Commented two lines are the one which I want to execute before
> creating pipelineJob.  Can anyone help with the syntax? Or anyother method
> to loop array values and create pipeline job and other script execution.
> Please help.
>
>
>
> create_job.groovy
>
> =================
>
>
> def apps = [
>
>
>    [project:"myproj",repo:"my-test-repo1"],
>
>    [project:"testproj",repo:"my-test-repo2"],
>
>    [project:"myproj",repo:"my-dev-repo"]
>
> ]
>
>
>
> apps.each {
>
>        app ->
>
>
>        //mystashurl = 'mybaseurl+scm/'+app.project+'/' + app.repo + '.git'
>
>        //sh("sed -i.bak -e 's#--GIT_URL--#${mystashurl}#' Jenkinsfile")
>
>
>        pipelineJob('LIB.' + app.repo.replaceAll('-','')) {
>
>        description('Containerized microservice lib config')
>
>
>
>        definition {
>
>         cps
>
>         {
>
>             script(readFileFromWorkspace('Jenkinsfile'))
>
>             sandbox()
>
>         }
>
>     }
>
>
>
>    }
>
> }
>
>
>
>
> Thanks,
>
> Sakthi
>