Single Jenkinsfile, multiple architecture builds

741 views
Skip to first unread message

Roberto Aguilar

unread,
Aug 4, 2016, 9:39:49 AM8/4/16
to Jenkins Users
Hello,

I have a Jenkins master (x86_64 linux) and a slave (armv7l linux).  I have labeled them "x86_64" and "arm" respectively.  I have a Pipeline build triggering on Git push, and I would like the Jenkinsfile in the repo to build on both machines.  I'm having trouble setting up my Jenkinsfile to do this.  My attempt errors out with the message:

```
ERROR: The ?stage? step must not be used inside a ?parallel? block.
```

The goal here is to:

- build two docker images; one for arm and x86_64
- keep from duplicating the build stages in two `node {}` definitions, hence attempting to call the build() in each node
- run the builds in parallel rather than having to wait for one to complete before starting the other

Any pointers on getting this to work.

Thank you.


My Jenkinsfile:

```
def build() {
   stage 'repository'
   checkout scm


   stage 'vars'
   def git_tag = sh(returnStdout: true, script: '''git describe --tags || exit 0''')
   def arch = sh(returnStdout: true, script: '''uname -m''')


   stage 'Docker'
   def docker_base="${env.gitlabSourceNamespace}/${env.gitlabSourceRepoName}"
   def git_branch = env.gitlabTargetBranch.split('/').last()

   def docker_tag = "${docker_base}:${git_branch}-${arch}"

   docker.withRegistry('https://registry.gitlab.com/', 'gitlab-docker-registry') {
     def docker_image = docker.build(docker_tag, '.')
     docker_image.push()
   }
}

parallel (
  'arm': {
    node('arm') {
      build()
    }
  },

  'x86_64': {
    node('linux') {
      build()
    }
  }
)
```

Daniel Beck

unread,
Aug 4, 2016, 10:23:11 AM8/4/16
to jenkins...@googlegroups.com
The error just tells you that you can't define stages within parallel, as there's no visualization for it -- it's strictly sequential. So remove the 'stage' statements from build() and it should be fine.
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/555f7e28-f695-48d4-af4f-02a5883d1961%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Roberto Aguilar

unread,
Aug 4, 2016, 11:00:47 AM8/4/16
to Jenkins Users, m...@beckweb.net
Ah, perfect, works.

Thank you Daniel!

-Roberto.
Reply all
Reply to author
Forward
0 new messages