Accessing artifacts from previous run of the same build - continuous-integration

I want to implement rerun solution for flaky tests.
I have problem with passing artifacts from previous run on build to next build.
Artifacts B -> B (Run 2)
Is there any option to get artifacts from latest run of the same build in same snapshot? For now I know that only option would be to get artifacts from Teamcity API.

As was said before only option was to get latest build number from TC API and then get artifacts from API by this build number. There is no better option.
Get latest build:
https://teamcity.com/httpAuth/app/rest/builds?locator=snapshotDependency:(from:(id:$parentBuildId),includeInitial:false),defaultFilter:false,buildType:$buildTypeId,state:finished,failedToStart:false,canceled:false,count:1
Get artifacts:
"https://teamcity.com/httpAuth/app/rest/builds/id:$latestBuildId/artifacts/content/$failed_tests_filename"
I'm answering in case if someone else will look for solution.

Related

Share parameter with dynamic build configure ID in teamcity

I have a build chain with two jobs: B depends on A. B needs to get a build counter from A.
dep.btID.property name could share parameters from A to B.
However, the btID is dynamic create by git for each branch
I have add following to build steps of B(bash):
ABuildID=dep.dev_branch_A.env.BUILD_NUMBER
echo '%$ABuildID%'
or
echo '%${ABuildID}%'
It will lead to no compatible agent
Following could work however, I need to adapt to all branchs
echo '%dep.dev_branch_A.env.BUILD_NUMBER%'
Is there any way in TeamCity 9 to pass a build configuration parameter with dynamic btID from a project A to its dependency (in the same build chain)?
---------------------Update after finding the solution, hope it will help someone in the future------------------------
I have found a solution by request last successful build of projectA via rest api.
In bash:
curl -s https://teamcity_host_name/guestAuth/app/rest/buildTypes/dev_branch_A/builds?status=SUCCESS&state=finished&count=1
The response will provide the many parameter of project_A, build number is included
Please find introduction of teamcity rest API:
https://www.jetbrains.com/help/teamcity/rest-api.html#RESTAPI-URLStructure
Thanks Niraj Gajjar for the answser
You have add projectA in ProjectB as either Snapshot Dependency or Artifact Depedency ( for that go to Dependencies from left panel menu)
After that you can use build counter of ProjectA like
%dep.ProjectA.build.counter%
or
echo %dep.ProjectA.build.counter%

Pass/share parameter values between dependant builds in TeamCity

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

Moving files between build chain builds

What is the set up required to move files between builds in TC? I am needing to move both modified source files and build binaries between the build configurations of a build chain.
I have 1 project with 4 builds. The builds are
Update Version Number (This build updates 15 sources files)
Compile (This build compiles a dozen objects)
Test (This build runs a regression test)
Create Package (This build creates a setup.exe file)
Information about the TC setup and chain
I am using perforce as my VCS.
All 4 builds use the same VCS root.
On all 4 builds under version control settings I have "Clean all files before build" set to "On".
"Update Version Number" build is triggered by any check in to the VCS. (This works)
I have been able to successfully chain and trigger the builds. However each build starts with a fresh copy of files from the VCS.
The chaining is set up to use snapshot dependency.
Based off of the TC documentation it looks like I should be using snapshot dependency and not artifact dependency. If I put the build steps of all the builds into the same build everything works. However we are looking to have more flexibly and expand on this build chain in the future.
I tried setting up the configuration so only the first build is attached to the VCS root and the other builds don't have any VCS root. This didn't work.
I have been unable to find the answer googling but I have been able to find someone else who is struggling with this problem. Sadly they didn't receive an answer.
After speaking with TC customer support I learned the correct technique is to use both artifact dependency with "build from the same chain" selected and snapshot dependency.

Downloading builds from TeamCity

Is there a way to download specific builds of a project in TeamCity?
You can use the build id, build number or one of the static build identifiers:
http://{TeamCity-Server}/repository/download/{BUILD_TYPE_ID}/{BUILD_NUMBER}/{ARTIFACT_PATH}
http://confluence.jetbrains.net/display/TCD65/Patterns+For+Accessing+Build+Artifacts
What you're actually looking to do is create artifacts in TeamCity. Artifacts are normally a build output which are then attached to the individual build runs so that you can download and review them at a later date. There's a walk through including the creation of build artifacts in You're deploying it wrong! TeamCity, Subversion & Web Deploy part 5: Web Deploy with TeamCity.
we attach the .msi file generated from the build as an artifact containing the build number (you can use %env.BUILD_NUMBER% to find the artifact path).
As mentioned above, one can download using REST API. It is also possible using FluentTc library with fluent api:
Download artifacts of the latest successful build:
IConnectedTc connectedTc = new RemoteTc().Connect(a => a.ToHost("tc")
.AsUser("MYUSERNAME", "MYPASSWORD"))
IBuild lastSuccessfulBuild = connectedTc.GetLastBuild(having =>
having.BuildConfiguration(with => with.Id("FluentTc"))
.Status(BuildStatus.Success));
IList<string> downloadedFiles = connectedTc.DownloadArtifacts(lastSuccessfulBuild.Id,
#"C:\DownloadedArtifacts");
Download specific file from artifacts of specific build by build Id:
string downloadedFile = connectedTc.DownloadArtifacts(
buildId,
#"C:\DownloadedArtifacts",
"binaries.zip");
To get latest successful build artifacts from Team City you can use the following link templates:
with guest authentication: http://<buildServer>/guestAuth/downloadArtifacts.html?buildTypeId=<buildTypeId>&buildId=lastSuccessful
with your credentials: http://<buildServer>/repository/downloadAll/<buildTypeId>/.lastSuccessful/artifacts.zip
with specific artifact: http://<buildServer>/httpAuth/repository/download/<buildTypeId>/.lastSuccessful/<some file.ext>

hudson for newbies: how do i run software after successful build

i'm new to world of continuous integration and software developement.
I wanted to try hudson so i installed it on my ubuntu machine and created a new job. i pointed it to an open source project's svn (keepassx) just to try.
Hudson downloaded everything from the repository and marked blue for successful build.
aren't i suppose to be able to execute the software now somehow ? i thought once it is built i can run it, but i can't find any executable in the project's home page under hudson user home dir.
thanks.
A Hudson/Jenkins build breaks down into three steps:
update source code in workspace
run build
publish build artifacts
It sounds like you've got step 1 covered.
If the project you linked to has instructions for building (ant, maven, etc.), you can enter these as build steps into the "Build" section of the project configuration.
You can then take the resulting files ("artifacts"--jar, exe, so, bin, whatever) and publish these using the "Post-build Actions", or if necessary you can grab them directly from the workspace filesystem.
Assuming the build artifact was an executable, you could then run it after downloading it from Hudson, or make a build step or post-build action which moved it into the appropriate location and ran it.
It helps to run the build locally before trying to get Hudson to handle it--then you know what the build steps are, and what the final build artifacts are.
How would jenkins/hudson know how to 'execute' some arbitrary package that you told it to download and build? It's up to you to write a program or script to run what you want to run, and then make a downstream job (for example) to do so.

Resources