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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

Jonathan Ballet

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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/44511a85-e007-47df-8878-906c9d707283n%40googlegroups.com.