How to run per-build setups when a new build executes on a node?

23 views
Skip to first unread message

Jonathan Ballet

unread,
Jul 21, 2020, 1:44:51 PM7/21/20
to Jenkins Users

Hi,

We are running our Jenkins builds on EC2 using the ec2-plugin.

We have 2 types of EC2 nodes:

* very ephemeral ones, which are created and destroyed for each builds
* longer ones, which are created and destroyed once a day more or less

Our (scripted) Jenkinsfiles look like this:

node("short") { // or node("long-duration")
  // do the build
}

I'm looking for a way to have some kind of automatic per-build actions, that would run when a new build is executed on a node, without having to configure it in all my Jenkinsfiles.

We wrote a Groovy function to do that:

withSetup(Closure body) {
  // do some pre-build actions
  try {
    return body()
  } finally {
    // do some post-build actions
  }
}

But we would need to add that call in all our Jenkinsfiles, and I don't have way (IMO) to *enforce it* in all my builds: if a developer missed it, then the pre/post-build actions won't be executed.

Is there a way to configure this type of function per-node / per-build automatically?

Thanks!

 Jonathan
Reply all
Reply to author
Forward
0 new messages