Is there a way of declaring a block of Groovy configuration code and 
reusing it in several places of a Groovy configuration script? Say I have 
a  sequence of steps to fetch and unarchive an artifact:

stage('Stage1') {
  jobs {
    job('Job1') {
      tasks {
        fetchArtifact {
          pipeline = 'MyPipeline'
          stage = 'Build'
          job = 'Artifact1'
          source = 'util.tgz'
          file = true
        }
        bash { commandString = 'tar -xzf util.tgz' }

This sequence is common for all stages so I'd like to wrap it in a reusable 
object and call it in all relevant places, something like (not working, 
only for illustration):

def fetchUtil() {
  fetchArtifact {
    pipeline = 'MyPipeline'
    ...
  }
  bash { commandString = 'tar -xzf util.tgz' }
}

stage('Stage1') {
  jobs {
    job('Job1') {
      tasks {
        fetchUtil()
        bash { commandString = 'run some other commands' }

Can I do something like this? The best I can think of is to declare 
closures with attributes and pass them to individual fetchArtifact and bash 
tasks:
fetchArtifact fetchUtil
bash unarchiveUtil
but can I declare a sequence consisting of multiple tasks and reuse it 
later in the code?
I am aware of the task plugin but in my case it would be too complicated, 
all I'm looking for is how to combine a few available tasks into something 
Groovy can understand.

Thahks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"go-cd" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/go-cd/55988ad1-11f6-4879-8289-40d39cc4031en%40googlegroups.com.

Reply via email to