I would like to use a property, which I defined inside my pom.xml. Now I would like to refer to this property value inside my TeamCity Build Step.
At the moment I'm only able to refer the other way around to use a TeamCity property inside Maven.
In particular I want to do a SSH Deployer with a target like url/path/%maven.output.type%/something with
<properties>
<!-- Art der Entwicklung -->
<output.type>testing</output.type>
</properties>
What I tried was to define a parameter in TeamCity but I have no idea how to define the value of this parameter.
Is there any way to use this property inside the TeamCity build?
You can run a script that will set a teamcity parameter that you can use in a another build step. Here are the build configuration settings I use:
Create a configuration parameter with an empty text value with a name used in the next step (e.g. outputType).
Add a build step, with runner type Command line:
Select to run a custom script.
In the custom script field, enter a script that will extract the value from the pom file, and tell teamcity to set it in the parameter. For example:
testing=sed -n 's:.*<output\.type>\(.*\)</output\.type>.*:\1:p' pom.xml
echo "##teamcity[setParameter name='outputType' value='$testing']"
This will set the teamcity parameter outputType with the value of an element named output.type found in the current project pom file.
In another build step, you can use that parameter in a field like, for instance, the target field:
somepath/%outputType%
Related
How can we pass the persistent object store 'true' value through mvn command to get the trick mark in runtime manager for RTF applications? As of now, we are not passing objectstore through the pom file, but we need to do so through Jenkins script.
CMD: mvn deploy –DmuleDeploy -DobjectStore = true
Will this cmd -DobjectStore = true work or are there any other options?
Using the Mule Maven Plugin for Mule 4 in the <deployementSetting> section add the element <persistentObjectStore>. Its value will be the property that you are defining in the command line. For example:
<persistentObjectStore>${objectStore}</persistentObjectStore>
Then you can define the property value in the command line to set it to true or false: mvn deploy -DobjectStore=true ...
I am trying to setup a Jenkins pipeline to trigger builds using gradle for multiple environments.My requirement is that the artifacts produced when I run gradlew clean build should produce artifacts with name indicating the environment for which the pipeline was run. Example my-application-dev.jar
The value of the environment would be selected by the user when build will be triggered.
What is the optimal way to achieve this ? Does build allow to configure any such property via command line or do I need to define a task in my build.gradle and define properties within that task for which I will pass value from command line
There are basically two ways.
The first one is to pass these naming-relevant pieces of information to the gradlew process, e.g. via -D or -P properties.
Then you need the Gradle build to be aware of these parameters and craft the artifact names it produces accordingly.
The second one is arguably better and more contained. You simply rename the artifacts produced by the gradlew command after it completes, in the Jenkinsfile. This works well if the pipeline decides what to do with these artifacts (e.g. publish to a repository) as opposed to the gradle script doing it (in which case you would most likely be better off using the first method).
Passing the version to POM.xml.
It shows warning. 'version' contains an expression but should be a constant.
I have to remove this.
I have one Ant project and another maven project. I made one runconfiguration for Ant project where I made one variable with some value suppose 13.2.1
by opting external tool configuration that variable come in list now.now able to pass that variable like -Dversion="${versionjar}".
its working perfactly.
since this versionjar is already set in eclipse. I want to use this while I want to run the maven project by runconfiguration.
want to pass in create manage and runconfiguration like in goal section install -Dversion="${versionjar}" but its not working .
I have to set this variable here also by add button.
How can I pass the variable from eclipse command line like :install -version="${version}"? version is vailable in eclipse variable list while "${version}" is properly send to pom when it is hard coded.
"${version}" is not resolving when send in goals section of run configuration
I'm facing problem when passing the eclipse variable from command line configuration.
in POM
<version>${version}</version>
<packaging>jar</packaging>
We have a CICD process in place with defined set of TCs executed always for gating process. Sometimes its not needed to run all tests, instead we would like to trigger only set of TCs based on change made by developers. Our tests are cucumber based User Stories and hence we can control the test run by Tags. My idea is to parameterize cucumber.options from teamcity's maven command line parameters field and let Dev/support people define the tag as needed.
If i mention command line parameter as
-Dcucumber.options="--tags %env.test.scope%"
my mavenized project gets the value as cucumber.options = "--tags #Sanity (Assume env.test.scope value is #Sanity). If you note here closely, why am i getting opening double quote? It ruins my TestRunner and none of the tests are triggered. If i remove double quote, then i get mvn error as #Sanity is not recognized as valid goal (because of space issue between --tags and #) how to define my parameter (cucumber.options) value with space in it?
This seems to be more related to JVM (to run Maven) and -D than TeamCity. The correct way to pass the parameter would be
"-Dcucumber.options=--tags %env.test.scope%" as it should get as a single parameter to JVM and then be parsed to "cucumber.options" parameter with "--tags %env.test.scope%" value.
Here's my scenario:
Maven 2.0.9 is our build system
We install code to multiple environments
All of our environment-specific properties are contained in property files, one for each environment
We currently read these properties into maven using the properties-maven-plugin; this sub-bullet is not a requirement, just our current solution
Goal:
Perform certain parts of the build (ie. plugin executions) only for certain environments
Control which parts are run by setting values in the environment-specific property files
What I've tried so far:
Maven allows plugins executions to be put inside pom profiles, which can be activated by properties; unfortunately these must be system properties - ie. from settings.xml or the command-line, not from properties loaded by the properties-maven-plugin
If possible, we'd like to keep everything encapsulated within the build workspace, which looks something like this:
project
pom.xml
src
...
conf
dev.properties
test.properties
prod.properties
build-scripts
build.groovy <-- the script that wraps maven to do the build
install.groovy <-- ... wraps maven to do the install
Running a build looks like:
cd build-scripts
./build.groovy
./install.groovy -e prod
Is there any possible way to accomplish these goals with the version of maven we are using? If not, is it possible with a newer version of maven?
This isn't possible using just Maven. (See also How to activate profile by means of maven property?) The reason is that profiles are the first thing evaluated before anything else to determine the effective POM.
My suggestion is to write some preprocessor that parses your environment specific property files and converts them to the required system properties before launching Maven. This script can be included in your ~/.mavenrc so that it runs automatically before Maven is launched. Here is an example script that that assumes the properties file is in a fixed location:
properties=`cat /etc/build-env.properties`
while read line; do
MAVEN_OPTS="$MAVEN_OPTS -D$line"
done <<< "$properties"
If the properties file is not fixed, you'll just need to add something to the script to discover the location (assuming it is discoverable).