1

I want to add similar stages to Jenkins pipeline, something like:

pipeline { stage('Publish archives to Artifactory - common') { steps { dir('android/build/artifacts_output/common') { script { def server = Artifactory.server 'artifactory' def uploadSpec = """{ "files": [ { "pattern": "*.*", "target": "my-repo/1.0.0/common" } ] }""" server.upload(uploadSpec) } } } } stage('Publish archives to Artifactory - core') { steps { dir('android/core') { script { def server = Artifactory.server 'artifactory' def uploadSpec = """{ "files": [ { "pattern": "*.*", "target": "my-repo/1.0.0/core" } ] }""" server.upload(uploadSpec) } } } } } 

I need to add some more stages like this, for different modules. Is there a better way to do it, like adding stages with loop, instead of copy-pasting this code many times?

This snippet is written in Groovy. I'm not familiar enough with the syntax of Groovy...

EDIT

Also found this similar question

1 Answer 1

2

One possible approach would be to provide a list of configuration objects and then iterate over the list

def list = ["Conf 1", "Conf 2", "Conf 3", "Conf Last"] list.each { stageName -> node { stage(stageName) { println(stageName) } } } 

In your case you would rather need maps or some other kind of parameter objects in the list.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank! So all I need is to put the stages in 'node', and they will be added to the pipeline?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.