Gracefully ignoring unavailable agents

13 views
Skip to first unread message

Mark Raynsford

unread,
Dec 31, 2020, 4:27:08 PM12/31/20
to jenkins...@googlegroups.com
Hello!

Let's say I'm using a declarative pipeline setup like this:

~~
#!groovy

pipeline {

agent none

stages {
stage('Build') {
parallel {
stage('Build Linux') {
stages {
stage('Build:linux:openjdk-11-hotspot') {
agent {
label 'linux'
}
...
}
stage('Build:linux:openjdk-15-hotspot') {
agent {
label 'linux'
}
...
}
}
}

stage('Build Windows') {
stages {
stage('Build:windows:openjdk-11-hotspot') {
agent {
label 'windows'
}
...
}
stage('Build:windows:openjdk-15-hotspot') {
agent {
label 'windows'
}
...
}
}
}
}
}
}
}
~~

As you can see, I use labels to select agents to run builds on specific
operating systems and with a fixed set of specific JDK versions. This
all works fine. However: With my current hardware setup, the Windows
node is _not_ going to be online 24/7 (the Linux node is always
available).

Is there a way I can adapt the above pipeline to basically say "If
there's a Windows node online, run the stages, otherwise trivially
succeed"? Right now, if no Windows node is available, the pipeline will
hang until either one becomes available or the entire job times out.

--
Mark Raynsford | https://www.io7m.com

Mark Waite

unread,
Jan 2, 2021, 12:30:46 PM1/2/21
to Jenkins Users
--
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/20201231212628.447a21b5%40sunflower.int.arc7.info.

Mark Waite

unread,
Jan 2, 2021, 12:35:04 PM1/2/21
to Jenkins Users
Apologies for the empty message that preceded this one.  Fat fingers on an unfamiliar keyboard.

I've been using the pipeline step 'nodesByLabel' in scripted pipelines to select label based subsets of agents that are currently available.  I'm not sure that the same technique can be used with declarative pipeline.

ST

unread,
Jan 4, 2021, 4:34:23 PM1/4/21
to Jenkins Users
As mentioned by Mark, nodesByLabel will give you control over what agents are currently available. But you will need a script {} section in an initialization stage and probably set an env variable that you then check in the when {} section of the windows stages. So not purely declarative anymore.

Another idea (in case you are not aware of this yet) would be to set a very short stage-specific timeout for the windows stages only. The windows stages will then show as ABORTED, but since the Linux stages are run in parallel they should still go ahead and run.

Mark Raynsford

unread,
Jan 5, 2021, 4:35:26 PM1/5/21
to ST, jenkins...@googlegroups.com
On 2021-01-04T22:33:55 +0100
ST <st.mail...@gmail.com> wrote:

> As mentioned by Mark, nodesByLabel will give you control over what agents
> are currently available. But you will need a script {} section in an
> initialization stage and probably set an env variable that you then check
> in the when {} section of the windows stages. So not purely declarative
> anymore.
>
> Another idea (in case you are not aware of this yet) would be to set a very
> short *stage-specific timeout* for the windows stages only. The windows
> stages will then show as ABORTED, but since the Linux stages are run in
> parallel they should still go ahead and run.
> Stage timeout documentation:
> https://www.jenkins.io/doc/book/pipeline/syntax/#stage-options

Thanks, both of you!

I think I might go another way: Throw hardware at the problem and
arrange to have a Windows node that's actually on 24/7.
Reply all
Reply to author
Forward
0 new messages