Retrieve parameters from properties file - build

I have several Jenkins parameterized jobs that uses the same parameters and parameters values.
When I have to change the default value of one of those parameters, I need to go over all of those jobs and reconfigure them.
A simple solution to this problem would be an option to retrieve all parameters from config file (in the master/ in the workspace) but I could not find a sufficient implementation for that.
I want to be able to feed build with standard Java config file (in format "key"="value") and then refer to those parameters like every other parameters during the build.
Do you know of an appropriate solution?

Use EnvInject Plugin to read your parameters from a file as environment variables in an Inject Environment Variables build step. The glitch is that then you can't override them easily. One solution would be to use it in conjunction with the Conditional BuildStep Plugin. You can then can define a boolean parameter OVERRIDE that would be false by default. You can then run your Inject build step conditionally only when OVERRIDE is false. When you need to override your parameters with values provided by hand (on in a custom call to run the job) specify the override values and set OVERRIDE to true.

I use hudson with ant and set parameters (customer) in my hudson job. This parameter is then the name of a property file that i open with ant as follow:
<loadproperties> srcFile="${project.dir}/build/resources/${customer}.properties"/>

Related

How do you add a custom kustomize transformer?

I'd like to add a transformer to my kustomize setup, one that includes a dynamic value for the case where the local tag needs to override the production tag. If there's a simpler and better way to do this that would be great. I've looked through the list of transformers and generators to see if there was a way to provide this value at runtime (though I think specifically kustomize is designed to never use runtime values).
I can specify something like this:
images:
- name: my-image
newTag: my-sha1
The problem is to change the my-sha1 value after each new local build to then pick that image when I go to apply the local deployment.
How can I set newTag after I run a build locally to match a tag for the image I made locally? I can easily obtain the latest build tag and provide with to kubectl apply -f, but I'm not seeing a flag or environment variable, or something to do so.

Keeping preset (non-default) values when calling boost parseOptions

In my project I've got some internal config structures containing options registration using default values (let's say Config.x=0, Config.y=0), those values are not modifable for a client.
Sometimes users of my application want to modify default values of those fields before parsing command line arguments, so before parsing they just change those values manually (let's say Config.x=3, Config.y=4) and then fetch command-line/.ini ifle options and parse it using parseOptions.
If those external arguments contain only a part of those options i.e. Config.x=9, values of other options will be those which are registered using boost::program_options, not those currently assigned, so the result would be Config.x=9, Config.y=0 instead of Config.x=9, Config.y=4. So basically it seems that, boost::program_options::parseOptions clears all options before parsing.
Is there anyway to prevent boost from clearing already assigned options in case they do not appear in command-line arguments?
This can't be done. However, you should be able to create parsed_options either manually¹, or you can supply the options as a "faux" configfile so you can actually use the configfile parser on it.
Once you have the parsed_options you can store/notify them as usual.
¹ though this isn't supported/documented, see the comment at boost::program_option::basic_parsed_options<>

Teamcity - Make a Configuration parameter mandatory from Template

In Teamcity 9.*
I have a Build Template with some Configuration parameters that will be different depending on the project that will be created from it.
This parameter is important and must be entered during creation otherwise the build will not work. So my question is:
Is there a way to configure this parameter as Mandatory during Build Creation Dialog?
Teamcity actually has the Name field as mandatory.
I tried to define the parameter as "Text" and with validator "Not Empty". Also using the REGEX but without success. This kind of validator seems to work only running the Custom Builds.
No, unfortunately there is no way to achieve this.
The only way to see this is by looking at your parameters after you've created a build configuration from a template and this will show the required parameters (i.e. they are referenced in build steps / other variables somewhere)
Here you can see a configuration based on a template. The values aren't set in the template or at the point of creating the build configuration
If you fail to supply any of these values, then your build will sit in the build queue and the error message will be "unable to run on any agents due to missing parameter values"

Jenkins Flexible Publish plugin if else condition

I am using the flexible publish plugin for jenkins and found it very useful. My goal is to pass a set of predefined parameters from a job to trigger another downstream job. The downstream job performs an action based on the string match evaluation. But if i dont pass the parameters the job would fail saying
Exception caught evaluating condition: [org.jenkinsci.plugins.tokenmacro.MacroEvaluationException: Unrecognized macro 'multinodeind' in '${multinodeind}'], action = [Fail the build]
I want to do an if else flow. If the parameter is present evaluate it and proceed. Otherwise perform another action. Any clue?
You know you can add parameters with default values under Meta Data → ☑ This build is parameterized → Add parameter, do you? The default values are supposed to be taken if a value for a parameter isn't passed, IIRC.
However, you can use the Conditional BuildStep Plugin in the project configuration's Build section:
A buildstep wrapping any number of other buildsteps, controlling their execution based on a defined condition.

How to build project from another project in TeamCity?

Suppose we have a build project which takes a list member as a parameter.
Can I make another build which could run the first project with all parameters from list sequentially?
If I understand you correctly you want to reliably trigger multiple builds of type A based on a list you pass to build B.
What you could do is have B parse the list (using powershell or whatever else custom program you want to use) and then use the TeamCity REST API to trigger builds of type A with the right parameters, the syntax described here would apply to this:
To trigger a build with custom parameters (system properties and
environment variables), use:
http://testuser:testpassword#teamcity.jetbrains.com/httpAuth/action.html?add2Queue=bt10&name=&value=&name=&value=
This allows you to pass the parameters you need for each build.