Teamcity - save build parameters in produced artifact - teamcity

I build j2ee aplication as WAR with teamcity.
I want keep the same WAR name and save build parameters in produced artifact.
What the best way to save teamcity build parameters (like build.number, svn.revision, buiild.date etc) inside it?

Something like
echo build.number=%build.number% > prop.properties
is what I do in a TeamCity build step to directly record parameters to a file.

Related

Pass a file as a property while calling a maven goal in Jenkins v2.263.1

I am migrating all my jobs from Jenkins v1.651.3 to Jenkins v2.263.1.
Currently I am passing a file stored in my Linux server as a property under Invoke top-level maven targets build step in Jenkins.
e.g. property.a=/home/user1/props/a.properties and property.b=/home/user1/props/b.properties
In Jenkins v2.263.1, I am running all my jobs in a docker container which is created dynamically.
Where and how can I store this file so that I can pass this as a property to maven build like -Dproperty.a=/home/user1/props/a.properties and -Dproperty.b=/home/user1/props/b.properties
I tried adding these files in Managed Files section under Manage Jenkins option and passing these as -Dproperty.a=a.properties to maven build through Jenkinsfile, however, it did not work. Not sure if it's the right way.
Please let me now if there's a way to handle this.
Thanks in advance!

How to set name of the artifacts produced from Gradle to values passed from Jenkins pipeline

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).

In teamcity, can an artifact be executed in a build step?

For example, project A generates two artifacts processor.exe and t.txt. Then in project B, can I add a build step to execute processor.exe t.txt?
I know there are two Runner types(.NET Process Runner and Command Line) that can execute programs. But how to get the paths of these artifacts?
Yes, I think it should be possible to run with Command Line runner *.exe file generated by other build.
You just have to make sure that build agent which runs Project A outputs these artifacts to place where build agent which runs Project B has access (in case if you have single agent it's not a concern obviously). And probably placing these artifacts into agent's working directory is not the best place because it can be cleared by doing clean checkout from VCS. Just choose some generic directory on the server and specify it for artifact output in Project A and then for Command Line runner in Project B.

get a link in jenkins to deployed artifact

I have a job in jenkins that assembles zip package and deploys it to nexus. At the end of logs I get urls to this uploaded package. Next I would like to get this url somehow and pass it to next jenkins job, but I don't know how to retrieve this link from logs. Any idea how to do that?
I can think of 2 quick options, you could parse the log with the scripting language of your choice in the next jenkins job using the [JENKINSURL]/job/[JOBNAME]/lastBuild/consoleText or if what you actually need is just the artifact you could have jenkins "Archive the artifact" and then the "Copy artifacts from another project" to pull it into the second job.

How can I get TeamCity to verify a generated file

My TeamCity build runs my build successfully, but I need to verify it is generating a specific file.
Specifically I can run gradle assemble for Android, but I need to know if a specific .apk file is created and fail if not.
I've tried setting the apk as an artifact, but I cannot fail if artifact wasn't created. Is this possible?
I've tried setting the apk as an artifact, but I cannot fail if artifact wasn't created.
Create script (i.e. bash/perl/php etc) to test what you need and make if fail (return 0 as return code) when your requirement is not met. Then invoke this script as separate build step in your project.

Resources