Portable Kotlin DSL Settings: Configure 'Finish Build Trigger' by parent configuration parameters in shared projects
I have a project using the Portable Kotlin DSL that I want to Share between multiple parent projects. The differences between the shared uses are:
* A parameter-value used in a Gradle call. I used this by defining an environment parameter in the parent project and use it in the Gradle build step with an '%env.my_parameter%' expression
* A 'Finish Build Trigger' with an id that is configured per-use of the shared build. So in "Project A" it should be triggered by 'some_project_x' and "Project B' should be triggered by 'some_project_y'
So far I don't have an idea how to achieve the second requirement. Since the id of the triggering build step is required when the Kotlin DSL is run the configuration parameters of the parent project don't seem to be available.
Any suggestions?
Please sign in to leave a comment.
Hi Alexander,
because the idea of the portable DSL is to be able to move it around, the parameters of parent projects won't be directly available for usage, but they should be resolved properly on the server. You could have a parameter named equally across parent projects that can be reused by the child projects.
Would that work for you?
As I've written I'm already using this mechanism in a build step.
However when defining a trigger after finish build trigger the parameters are not available since the are required while the script is run.
Hi Alexander,
sorry, I think you misunderstood me but my information wasn't fully correct either. I meant setting the Finish Build Trigger to use a parameter, as we usually allow using parameters in pretty much every configuration option. That way, you could set the trigger via a parameter and not have to depend on anything else.
I'm afraid I overlooked that you cannot use a parameter to have a reference on this particular field, though, so it's irrelevant. In Kotlin DSL, the build ID needed to be added to the trigger is simply a string with the build configuration ID, so if you have a way of retrieving it, you could use that. Because the DSL will run the code, you should be able to use code to actually locate the project and set the appropriate ID. If you need to have it dynamically added, that is. If it's from a subset of a small amount of projects, you could just keep a mapping of current project - id of the build and that should do the trick?
I ended up hard-coding a map into the script that maps the DSLContex.parentId to one or more strings containing the build ids. Of course this solution is very ugly. I'm even not able to load the mappings from a file (let's say a properties file).
Maybe it's worth a ticket?