Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Dynamically set container image when running Kubernetes cloud profile #4574

tdeemer ·

I have a Kubernetes cloud profile where I would like to set the container image based on a variable from the build configuration. Based on some attempts to call vars.get and request.variables in the "Docker Image" setting, it seems like variable information is not available in the context of a cloud profile (a null pointer exception is thrown just by trying to call vars.get).

Is this intended behavior or is there another way to set the image dynamically? For this use case, creating a separate cloud profile for each image would be difficult to manage.

  • solved #2
  • replies 7
  • views 554
  • stars 0
robinshen ADMIN ·

Unfortunately it is not possible to use request/build variables in cloud profile, as cloud profile needs to be created/maintained separated from builds.

tdeemer ·

My use case is to replace a "Run docker container" step with an equivalent step that runs on Kubernetes instead. The current step relies on the image being set at build time, so it sounds like the only way to do that would be to create a cloud profile at build time. Is it possible to create the cloud profile via a groovy script in a build step?

robinshen ADMIN ·

That will not work, as cloud profiles are expected to be exist before any builds using it started and managed independent of the builds.

drdt ·

Robin, what if we had separate job to set up cloud profiles via API? We have a lot of them and expect them to change periodically. Basically the model would be something like

  • generate new build container
  • generate cloud profile for new container
  • update source to reference the new cloud profile when building

Or can you suggest another approach to better automate this?

robinshen ADMIN ·

Robin, what if we had separate job to set up cloud profiles via API? We have a lot of them and expect them to change periodically. Basically the model would be something like

generate new build container
generate cloud profile for new container
update source to reference the new cloud profile when building
Or can you suggest another approach to better automate this?

This approach should work if the build does not need to use its created profile. For details on how to create/edit cloud profile via API, please check:

Or you can interact with groovy using same approach as outlined in CloudProfileResource.java

drdt ·

Robin, you know I have always been a troublemaker. So after trying what you suggested above, we took it one step further (I have been working with Tyler). We have a job like this:

  • master (on server): sequential step
    • create-cloud-profile (on server): groovy script that creates a cloud profile, sets attribute "CLOUD_PROFILE=$profileName"
    • use-cloud profile (on agent with attribute "CLOUD_PROFILE=$profileName"): "hello world" script.

This works for us! The second step creates a new build agent from the newly-created cloud profile and uses it. Is this because the cloud profile exists before starting the step that needs it? Your statement before indicated that the profile needs to exist before the build starts, but we seem to have found a back door...

However, I don't want to try this in production without understanding the implications. I can send you the code for your examination.

robinshen ADMIN ·

No problem at all. This approach works as you only use created cloud profile in subsequent steps. I thought master step of the build uses the cloud profile previously.