Using TeamCity, I've set up several builds in a project. Most of the time I want to run each build as a standalone. However, sometimes I want to execute several builds with the same set of parameters. The builds all use the same template, so all of their parameters could, theoretically, be supplied by a single build.
I can't find anything in the documentation that says this is possible, but it seems like it should be. (searching for "execute builds from another build in teamcity" gives me plenty of documentation on build dependencies, but not what I'm looking for)
I know I can manually queue up all of my builds, but that would require re-entering the same parameters each time.
Does TeamCity support build steps that execute other TeamCity builds? If so, How?
Not exactly. However, in TeamCity you can have a build chain (builds the invoke other dependant builds) by adding a snapshot dependency.
If you add a snapshot dependency on another build configuration, then you can access all its defined parameters and even source and artefacts.
I achieve this by calling the TeamCity REST API:
Add a new step at the end of your build, using Command Line runner
Do curl
curl -X POST -H "Authorization: Bearer %TeamCityToken%"
--header "Content-Type:application/xml"
-d"
<buildType id="Remote Deploy"/>
<property name="tag" value="%NewVersion%"/>
"
http://teamcity.example.com/app/rest/buildQueue
You will need to change:
TeamCityToken to your access token, refer to this page to create one: https://www.jetbrains.com/help/teamcity/rest/teamcity-rest-api-documentation.html#REST+Authentication
Build type id "Remote Deploy" to your build type id.
The properties to whatever you need.
And, of cause, the teamcity url.
Related
Setup: Build CD has has Artifact Dependency and Snapshot Dependency on Build CI. Build CI pulls from VCS root and generates artifacts for Build CD.
Problem: In Build CD I need %teamcity.build.branch% parameter, but it's not available, because it only uses artifacts and has no VCS Roots linked.
Question: Is there a way to pass parameters between dependant builds? (search results in the googles seem of topic)
Workaround 1: I can access %teamcity.build.branch% in Build CD if I link it to same VCS root Build CI is using, but I'd like to avoid having this link and Build CD unnecessarily pulling from VCS (build log shows it does this).
Workaround 2: I could write parameter to a file in Build CI and read from it in Build CD later. This is a hack and I would like to avoid it as well.
Absolutely. In CD, add a parameter called whatever, with value equal to %dep.Build_CI.teamcity.build.branch%. TeamCity will help you figure out the exact value thanks to its auto-suggestion/auto-completion, once you type %dep..
I have a Jenkins job that uses a script to build my project. On the following line, the script fails mvn -e -X -Dgit='$git' release:prepare.
Because I want to search for the cause of this, I want to go to the Jenkins server and run mvn -e -X -Dgit='$git' release:prepare from the command line, to see if it works.
Does Jenkins store the projects' source code somewhere, such that I can go to that folder and call Maven?
If yes, then where?
Yes, It Stores the project files for the job by default at
/var/lib/jenkins/workspace/{your-job-name}
This is where jenkins suppose the project files to be present or it pulls it from a source before start working/building from it.
Quote from Andrew M.:
"Hudson/Jenkins doesn't quite work that way. It stores configurations and job information in /var/lib/jenkins by default (if you're using the .deb package). If you want to setup persistence for a specific application, that's something you'll want to handle yourself - Hudson is a continuous integration server, not a test framework.
Check out the Wiki article on Continuous Integration for an overview of what to expect."
From this Question on serverfault.
This worked for me:
/var/jenkins/workspace/JobNameExample
but, if your build machine (node) is a different than the one where Jenkins is running (manager), You need specify it:
/var/jenkins/workspace/JobNameExample/label/NodeName
Where you can define label too:
jenkins stores its workspace files currently in /var/jenkins_home/workspace/project_name
I am running from docker though!
I'm investigating a Maven/Jenkins/Artifactory set up as a possible solution for a CI/Release process.
I have a job in Jenkins - call it MYJOB - that builds and deploys an artifact to Artifactory. Now, I want another job that I can run manually that will copy the artifact of a particular build of MYJOB from Artifactory and put it somewhere (not too bothered where right now, but eventually it'll be another server).
For example, let's say build #123 went green, and now my QA team want to deploy the built artifact to their environment for further testing (the idea being to keep this artifact intact and unchanged throughout the testing process, before marking it as releasable). I want them to be able to enter '123' into Jenkins as a job parameter and then kick off the build.
So, I figure I need a free-style job that uses a script to do this.
My question is: How can I pass the number of a previous MYJOB build to the job, so that it will get the correct artifact from artifactory?
Alternative methods of achieving my goal are welcomed :)
So I got it working. I put the following code in the Build Step section of a Jenkins Freestyle Build Configuration after defining a parameter called 'REQ_BUILD_NUMBER':
SOMETHING=$(curl "http://MYARTIFACTORYLOCATION/artifactory/api/search/prop?build.number=$REQ_BUILD_NUMBER" | jq --raw-output '.results[0].uri')
echo $SOMETHING
SOMETHING_ELSE=$(curl $SOMETHING | jq --raw-output '.downloadUri')
echo $SOMETHING_ELSE
wget -N --directory-prefix=/var/lib/jenkins/artifacts/ $SOMETHING_ELSE
(NB: I'm barely competent at shell scripting. I'm sure it can be done in a better way)
EDIT: This requires installing 'jq' for the command line.
Create a Parameterized build for the second job. The QA team can put the build number when they start the build. This build number will be available as an environment variable which can be accessed in the scripts which can then retrieve the packages from the repository.
I'm trying to set/change a build parameter from build 1 to be used in build 2.
In build 1 I have a build step that sets a configuration parameter like this:
echo "##teamcity[setParameter name='ENVIRONMENT' value='%Target environment%']"
And in a build step on build 2, I want to use this environment variable in a rake task by
specifying %ENVIRONMENT%
The problem I have is that the configuration parameter is not visible in build 2. I have surely missed something essential.
I have also tried with env variables but that seems like the wrong approach as this is just configuration variables which is not needed in a build script.
Any clues?
Thanks
You can publish an artifact with the value you want in build 1, introduce an artifact dependency from build 2 to build 1, and in the first step of build 2 transform that artifact into a configuration value again for the other steps in build 2 by using the echo (or better Write-Host) statement you mentioned.
You can solve this in the same way I did for:
Is it possible to permanently update the value of a TeamCity build parameter as a result of a custom run?
Build 1 can update a variable which is being used in build 2 rather than build 2 trying to read a parameter in build 1.
Download and install CURL on build agent:
Add a command line step to build 1:
curl -v --request PUT -d "%Target environment%" --Header "Content-Type: text/plain" http://username:password#servername:8080/httpAuth/app/rest/projects/Build2Project/parameters/ENVIRONMENT
This updates the value of a parameter on a project, but you can use the REST API to update it on a particular build configuration if you prefer.
All REST.API documentation for TeamCity v8 can be found on their website
You can reference MyVariable variable which you set in Build configuration 1 in a script in Build configuration X such way: %dep.BuildConfiguration1Id.MyVariable%
I've used Google and looked at the Docs but can't find an answer.
I want to trigger another build or a rake script to do some cleaning up of files after a successful build. I currently use Rake to do my build and pass in %teamcity.build.branch% to it.
I would like to know if I can pass the same branch name of the successful build to the triggered build or script. I can then use this to do some tidying up.
Thanks
In addition to finished build trigger, you need to add snapshot dependency, with "Run build on the same agent" option enabled. This way, cleanup will run after each build, on the same agent.
You then will be able to refer to original build's branch name using dependencies parameters:
%dep.<original_bt_id>.teamcity.build.branch%