Team City 7.1 Configuration Parameters across Build Configurations - teamcity

I would like to define a variable on a TC configuration and would like to get its value on a different TC configuration that has a trigger dependency on the first one.
Is it possible to do this?

If both configurations are in the same project, you can define a build configuration template that contains the shared parameter (i.e. variable). Both active configurations must then reference that template -- use the 'Associate with Template' action to accomplish this. The value of the shared parameter must be set in the template in order for the same value to be known to both configurations.
If you're trying to share build numbers (or other system-level parameters) between the configurations, there is a special method for that.

I have to use something like this to actually dynamically change the configuration parameters.
Invoke-WebRequest -Uri "http://build/guestAuth/action.html?add2Queue=bt876&name=env&value=test&name=env.number&value=%target.env.number%" -Method "Get" -Verbose

Related

Use variables from settings.xml but override with environment variables in Maven

I'm trying to use a property in my Maven POM file to specify the URL / username / password to a private repository. I would like to get the value for this property from a settings.xml file (from either the global, user or project settings file) but use the value from a specific environment variable to override any of that if it is set.
I've searched a bunch and I've found some references to using build profiles which doesn't seem to be quite what I need, but then again I'm not very fluent in Maven so I might just be missing something there. I feel like an idiot because I would think this is a pretty common use case.
In general I'm not too keen on defining secrets (passwords or API keys) in environment variables but for now we need to do that to avoid having to change the whole CI pipeline.

How to get value of Configuration parameter in teamcity using Gradle?

I have been trying to get the value of configuration parameter since yesterday but no luck. On the documentation I can call it using this teamcity["<property name>"] but it wont work.
Say I have a configuration parameter called "isPaid". I want to get the "isPaid" param value in my gradle. How can I do that? Shouldn't that be
System.getProperty("teamcity[isPaid]")
Tried using both getProperty and getEnv but still did not work. Any ideas? Thanks
Configuration parameters (no prefix) are not passed into the build and are only meant to share settings within a build configuration.
https://www.jetbrains.com/help/teamcity/configuring-build-parameters.html

See parameters that are overridden from TeamCity template

Is there a way to see TeamCity configurations that override parameter defined in template?
I don't think so. What's worked for me in the past was to search through the project files on the filesystem. If you have many build configs, this will be faster than opening each of them in the GUI.
Search for something like this:
<param name="myParamInheritedFromTemplate" value="myOverrideValue" />
in <TeamCity data directory>/config/projects/**/*.xml. If it's absent in an XML file, that build config just inherits the value. If it's present, it overrides it.
It's hacky but it's quick.
There is a feature request https://youtrack.jetbrains.com/issue/TW-21212, please vote. Current workaround are to either search the raw XML files with the settings stored under TeamCity Data Directory on the server as #sferencik suggested, or use REST API to get settings of all the build configurations and search for the parameter there. Let me know if you need help on any of these.

Getting settings object from the buildscript

I am trying to access the settings object from the root project's build script.
The reason is I want to define a list in the settings.gradle file which will be a list of subprojects, kind of:
settings.gradle
projectNames = ['prjA', 'prjB']
Would like to do something like:
build.gradle (root project)
projectNames = settings.projectNames
// Use projectName in tasks
And then access it in build.gradle for various tasks, such as resolving those names into URLs to git-clone them. However I can't seem to find a way to declare some arbitrary groovy object which is visible between these two scripts. Note I may potentially like that list to be related but not equal to the project names. I guess the question sums up to sharing POGOs between those two files and accessing the settings object.
I'm pretty new to Gradle.
There isn't a way to get to the settings object from a build script. However, both scripts share a gradle object, which you could use to set an extra property in the settings script (e.g. gradle.ext.foo = "bar"), and read it in the build script (e.g. println gradle.foo).
If you need access to the Settings instance from your build.gradle file after the
settings have been loaded and evaluated, you can register a lifecycle closure or listener.
A great place to start is the method Gradle#settingsEvaluated(Closure)
that provides the Settings object as a closure parameter.

Cruisecontrol.net project settings with dynamic parameters

I am trying to set up CruiseControl.NET (1.6.7981.1) so that each developer can choose which source-control branch to build from. I have encountered the following problems.
I have not found a way to set <artifactDirectory> and <workingDirectory> project parameters through dynamic parameters.
CruiseControl.NET is not replacing the dynamic parameter tokens, e.g. $[branchName] is not replaced in <artifactDirectory>C:/ci/$[branchName]<artifactDirectory>.
Is there a way to have a single project with multiple artifact and working directories chosen by end users?
No, you can not use dynamic parameters in <artifactDirectory> and <workingDirectory>. The documentation states:
Parameters can be used for tasks/publishers, source control blocks and labellers. [...]
Not all items allow the use of dynamic parameters.
If you are willing to relax on the single-project constraint, you could use the Configuration Preprocessor to define and apply a parameterized project template.

Resources