0

node label

I want to trigger Jenkins job on "hyp-z" and "hyp-x" build nodes. I tried to write it this way but getting "There are no nodes with the label ‘hyp-x&&hyp-z’"

  node ('hyp-z&&hyp-x') {
   // write something here
  }

What is the mistake I am doing and what is the exact working format?

daspilker
  • 8,154
  • 1
  • 35
  • 49
rameshthoomu
  • 1,234
  • 2
  • 17
  • 33

2 Answers2

0

This isn't possible in this form. The && expression is for narrowing down your pool of nodes for certain features. e.g. I want to run on a node which has the label UBUNTU and DOCKER. As opposed to running on two different nodes with those labels.

You can use parallel block to do what you are wanting. If you are using the Declarative syntax then see this article https://jenkins.io/blog/2017/09/25/declarative-1/ or here for scripted https://jenkins.io/doc/book/pipeline/jenkinsfile/#parallel-execution

apr_1985
  • 1,764
  • 2
  • 14
  • 27
  • Thanks for the quick response @apr_1985. In my scenario, I would like to run all stages on both z and x platforms. Could you please suggest me a script to execute this flow. Thanks in advance – rameshthoomu Jul 25 '18 at 16:44
  • I think for this case the only thing you could easily do is to define all your stages as individual methods, then the pipeline would be lots of parallel stages which just call the same method in the node blocks. – apr_1985 Jul 25 '18 at 18:17
  • 1
    Finally I have added below code snippet to make it work.. def labels = ['hyp-x', 'hyp-z'] def builders = [:] for (x in labels) { def label = x builders[label] = { node(label) { // build script } } } This worked fine to me.. But I see the log output of both platforms in one common job.. Is there a way to split this into two jobs? – rameshthoomu Jul 25 '18 at 19:05
  • Using the blue ocean plugin it'll be easier to separate the different logs. Or you use the 'Pipeline Steps' link. You'll get used to it :) Can you add the code snippet to your question as solution? – Joerg S Jul 26 '18 at 20:57
  • @JoergS The two approaches I have tried added as an answer. I am going with 2nd approach (Creating two Jenkinsfiles for each platform) – rameshthoomu Jul 27 '18 at 02:51
0

I have tried this in two ways

def labels = ["hyp-x", "hyp-z"]
def builders = [:]
for (x in labels) {
    def label = x
    builders[label] = {
        node(label) {
            // build script
        }
    }
}
parallel builders

Above code is working as expected from Jenkinsfile but I see both builds triggered in one common job and log looks clumsy. So I have tried 2nd approach like below

Created Jenkinsfile.x and Jenkinsfile.z and each file represents x and z platform build.

mike.dld
  • 2,929
  • 20
  • 21
rameshthoomu
  • 1,234
  • 2
  • 17
  • 33