TeamCity REST API: Triggering Build with Custom Artifact Dependency - teamcity

I'm trying to trigger a custom build using the TeamCity 8.1 REST API (see https://confluence.jetbrains.com/display/TCD8/REST+API#RESTAPI-TriggeringaBuild). My builds run fine and I'm able to specify custom branches and properties with no issue. My goal is now to specify a custom artifact dependency for the builds I'm triggering.
The response I receive when creating a build is something like the following:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<build taskId="1234" buildTypeId="buildConfig1" state="queued" ...>
<buildType id="buildConfig1" name="Build Config Name" ... />
...
<properties count="1">
<property name="testParam" value="Test 123" own="true" />
</properties>
<custom-artifact-dependencies />
</build>
The "custom-artifact-dependencies" tag in this response leads me to believe that there is a way to specify custom dependencies, but I have not found anything in the TeamCity documentation, the TeamCity forums, or from Google explaining how this can be accomplished. Is there something I'm overlooking here or another way of accomplishing this?
Adding the following to as a child of the "build" tag results in an "Artifact dependency should have type 'artifact_dependency'." error:
<custom-artifact-dependencies>
<artifact-dependency buildId="5432" buildTypeId="parentBuildConfig"/>
</custom-artifact-dependencies>
The server may be confusing my intention with the build configuration API for setting and viewing artifact dependencies (e.g. http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/artifact-dependencies/)

I had the same problem
This is what worked for me:
<build>
<triggeringOptions queueAtTop="true"/>
<buildType id="buildConfig1"/>
<custom-artifact-dependencies count="1">
<artifact-dependency id="0" type="artifact_dependency">
<properties>
<property name="pathRules" value="Artifacts_1.zip
Artifacts_2.zip
Artifacts_To_Unzip.zip!/**
"/>
<property name="cleanDestinationDirectory" value="true"/>
<property name="revisionName" value="buildId"/>
<property name="revisionValue" value="5432"/>
</properties>
<source-buildType id="parentBuildConfig" />
</artifact-dependency>
</custom-artifact-dependencies>
</build>
If the 'parentBuildConfig' build is still running, replace the buildId parameter with taskId

Related

maven resolver having issues : failed to create task or type resolve

I am trying to using the maven resolver in trying to migrate my ant projects to maven and using the below resolver tags:
<resolve failOnMissingAttachments="true">
<dependencies>
<dependency coords="org.apache.maven:maven-profile:2.0.6" />
<exclusion artifactId="junit" />
<exclusion groupId="org.codehaus.plexus" />
</dependencies>
<path refid="war.lib.path" classpath="runtime" />
</resolve>
instead of using the following :
<!-- retrieve depending libraries -->
<artifact:dependencies pathId="war.lib.path" useScope="runtime">
<pom file="pom.xml" />
</artifact:dependencies>
However I am getting the following error in replacing with maven ant resolver tasks:
Problem: failed to create task or type resolve
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
You are missing information to reproduce your issue.
However, with this minimalistic build.xml for demonstration, I got it going:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="maven-ant-task-resolver-demo" xmlns:r="antlib:org.apache.maven.resolver.ant">
<target name="resolve">
<property name="maven.ant.resolver.version" value="1.3.0"/>
<property name="maven.ant.resolver.jar.name"
value="maven-resolver-ant-tasks-${maven.ant.resolver.version}-uber.jar"/>
<get
src="https://repo1.maven.org/maven2/org/apache/maven/resolver/maven-resolver-ant-tasks/${maven.ant.resolver.version}/${maven.ant.resolver.jar.name}"
dest="." usetimestamp="true"/>
<taskdef uri="antlib:org.apache.maven.resolver.ant"
resource="org/apache/maven/resolver/ant/antlib.xml"
classpath="./${maven.ant.resolver.jar.name}"/>
<r:resolve failOnMissingAttachments="true">
<dependencies>
<dependency coords="org.apache.maven:maven-profile:2.0.6" />
<exclusion artifactId="junit" />
<exclusion groupId="org.codehaus.plexus" />
</dependencies>
<path refid="war.lib.path" classpath="runtime" />
</r:resolve>
</target>
</project>

TeamCity API work out how long investigation took to start?

Using the TeamCity API:
We are trying to put together a dashboard to work out how long from a build failing, it took for someone to assign themselves to an investigation for the build / project.
We cant find a way to do this as investigations are assigned to projects not builds so there is no way to find out when an investigation started for a particular build ?
If you need to get investigation for build configuration you may use the following REST API:
http://teamcity:8111/app/rest/investigations?locator=buildType:(id:XXXX)
For example, the following request
https://teamcity.jetbrains.com/app/rest/investigations?locator=buildType:(id:Epigenome_GenestackTests)
returns the following response, which has timestamp under assignment node:
<?xml version="1.0" encoding="UTF-8"?>
<investigations count="1" href="/app/rest/investigations?locator=buildType:(id:Epigenome_GenestackTests)">
<investigation id="buildType:(id:Epigenome_GenestackTests)" state="TAKEN" href="/app/rest/investigations/buildType:(id:Epigenome_GenestackTests)">
<assignee username="evgeny.kurbatsky" name="Evgeny.Kurbatsky" id="1107" href="/app/rest/users/id:1107" />
<assignment>
<user username="oleg" name="Oleg Shpynov" id="2" href="/app/rest/users/id:2" />
<timestamp>20160321T122158+0000</timestamp>
</assignment>
<scope>
<buildTypes count="1">
<buildType id="Epigenome_GenestackTests" name="Genestack Tests" paused="true" description="Fast tests" projectName="BioLabs :: Epigenome" projectId="Epigenome" href="/app/rest/buildTypes/id:Epigenome_GenestackTests" webUrl="https://teamcity.jetbrains.com/viewType.html?buildTypeId=Epigenome_GenestackTests" />
</buildTypes>
</scope>
<target anyProblem="true" />
<resolution type="whenFixed" />
</investigation>
</investigations>

Steps are not included in report

I'm creating reports, but steps are not included (look at screenshoot in the end of question!).
I've created ClassLibrary1 project in VS15
I've added NUnit3, NUnitConsole, Specflow and Specflow.NUnit nuget packages.
I've added defaul feature and step definition files.
After that, I ran these commands from cmd(first from nunit folder, second from specflow folder):
nunit3-console.exe --labels=All --out=TestResult.txt "--result=TestResult.xml;format=nunit2" D:\Projects\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll
specflow.exe nunitexecutionreport D:\Projects\ClassLibrary1\ClassLibrary1\ClassLibrary1.csproj /out:MyResult.html
As I see, steps are not included in output HTML file... I remember that it was working in previous versions, and i saw examples with button like 'expand', which should help to see exact steps been performed in scenario.
What do i miss?
TestResult.txt is
=> ClassLibrary1.SpecFlowFeature1Feature.AddTwoNumbers
Given I have entered 50 into the calculator
-> pending: StepDefinition1.GivenIHaveEnteredSomethingIntoTheCalculator(50)
And I have entered 70 into the calculator
-> skipped because of previous errors
When I press add
-> skipped because of previous errors
Then the result should be 120 on the screen
-> skipped because of previous errors
TestResult.xml is
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--This file represents the results of running a test suite-->
<test-results name="D:\Projects\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll" total="1" errors="0" failures="0" not-run="0" inconclusive="1" ignored="0" skipped="0" invalid="0" date="2017-02-28" time="12:37:46">
<environment nunit-version="3.5.0.0" clr-version="4.0.30319.42000" os-version="Microsoft Windows NT 10.0.14393.0" platform="Win32NT" cwd="D:\Projects\ClassLibrary1\packages\NUnit.ConsoleRunner.3.6.0\tools" machine-name="DESKTOP-417JV6U" user="dom" user-domain="DESKTOP-417JV6U" />
<culture-info current-culture="en-US" current-uiculture="en-US" />
<test-suite type="Assembly" name="D:\Projects\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll" executed="True" result="Success" success="True" time="0.386" asserts="0">
<properties>
<property name="_PID" value="25444" />
<property name="_APPDOMAIN" value="domain-" />
</properties>
<results>
<test-suite type="TestSuite" name="ClassLibrary1" executed="True" result="Success" success="True" time="0.379" asserts="0">
<results>
<test-suite type="TestFixture" name="SpecFlowFeature1Feature" description="SpecFlowFeature1" executed="True" result="Success" success="True" time="0.378" asserts="0">
<properties>
<property name="Description" value="SpecFlowFeature1" />
</properties>
<results>
<test-case name="ClassLibrary1.SpecFlowFeature1Feature.AddTwoNumbers" description="Add two numbers" executed="True" result="Inconclusive" success="False" time="0.118" asserts="0">
<categories>
<category name="mytag" />
</categories>
<properties>
<property name="Description" value="Add two numbers" />
</properties>
<reason>
<message><![CDATA[One or more step definitions are not implemented yet.
StepDefinition1.GivenIHaveEnteredSomethingIntoTheCalculator(50)]]></message>
</reason>
</test-case>
</results>
</test-suite>
</results>
</test-suite>
</results>
</test-suite>
</test-results>
Output html looks like:
You can generate the step definitions by right-clicking on the feature's text and selecting "Generate Step Definitions"
This will generate the Steps class but it will have only stub methods that throw a NotImplementedException.

catch failure with failonerror=false for <artifact:dependencies

I am using maven-ant-tasks-2.1.3 to pull dependencies from an Archiva repository.I get a failure when doing a re-deploy of a release to Archiva using existing Ant scripts.I cannot use Maven directly. I want to catch the failure and not cause a build failure.I have a property file for the variable values like groupId.
I tried to pull the dependency and it fails if it doesn't exist.
<artifact:dependencies filesetId="dependency.fileset" >
<remoteRepository id="central" url="http://mvn-repo....../archiva/repository/internal/"/>
<dependency
groupId="${groupId}"
artifactId="${artifactId}"
version="${version}"
/>
</artifact:dependencies>
I also get a failure when re-deploying an artifact to Archiva repo.
<target name="deploy-to-maven">
<artifact:install-provider artifactId="wagon-webdav" version="1.0-beta-2"/>
<artifact:pom id="deploypom" file="${basedir}/pom-entity.xml" />
<artifact:deploy file="${unzip.dir}/${target.jar.name}.jar">
<remoteRepository url="dav:${repository-uri}">
<authentication username="${repository.username}" password="${repository.password}"/>
</remoteRepository>
<pom refid="deploypom"/>
</artifact:deploy>
</target>
I was hoping to check if the file exists and then set an available property to false if it doesn't exist.Then i could check that property with target deploy-to-maven.
Thanks in advance for any tips,
Vijay
This sounds like a good time to use ant-contrib's trycatch task:
<trycatch>
<try>
<artifact:dependencies filesetId="dependency.fileset">
<remoteRepository id="central" url="http://mvn-repo....../archiva/repository/internal/" />
<dependency
groupId="${groupId}"
artifactId="${artifactId}"
version="${version}"
/>
</artifact:dependencies>
<property name="dependency.exists" value="true" />
</try>
<catch>
<echo message="Dependency cannot be resolved." />
<property name="dependency.exists" value="false" />
</catch>
</trycatch>

Using Maven settings.xml properties inside Spring context

I've got a Maven settings.xml file in my ~/.m2 directory; it looks like this:
<settings>
<profiles>
<profile>
<id>mike</id>
<properties>
<db.driver>org.postgresql.Driver</db.driver>
<db.type>postgresql</db.type>
<db.host>localhost</db.host>
<db.port>5432</db.port>
<db.url>jdbc:${db.type}://${db.host}:${db.port}/dbname</db.url>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>mike</activeProfile>
</activeProfiles>
<servers>
<server>
<id>server_id</id>
<username>mike</username>
<password>{some_encrypted_password}</password>
</server>
</servers>
</settings>
I'd like to use these properties twice
Once inside Maven's integration-test phase to set up and tear down my database. Using Maven filtering, this is working perfectly.
A second time when running my Spring application, which means I need to substitute these properties into my servlet-context.xml file during Maven's resources:resources phase. For properties in the upper section of settings.xml, such as ${db.url}, this works fine. I cannot figure out how to substitute my database username and (decrypted) password into the Spring servlet-context.xml file.
The pertinent part of my servlet-context.xml file looks like:
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>${db.driver}</value></property>
<property name="url"><value>${db.url}</value></property>
<property name="username"><value>${username}</value></property>
<property name="password"><value>${password}</value></property>
</bean>
The end goal here is for each developer to have their own Maven settings (and database on their own machine for integration testing)...And a similar setup on the Jenkins server. We do not want to share a common username/password/etc.
There is a way of filtering web resources by configuration of Maven War Plugin. Look at this for a snippet from official plugin's docs.
And by the way, I strongly recommend reconsidering this filtering-based way for providing de facto run-time configuration at build-time. Just notice that you have to rebuild the same code to just prepare package for another environment (or alternatively edit package contents). You can use application server's specific stuff for this (at least JBoss has one) or use Spring that AFAIR also can be configured like this.
I recommend you to use a property file in the middle. I mean: Spring application would load properties values form the property file using context:property-placeholder and Maven would be the one who replace ${...} variables using values from settings.xml using filtering.
Your property file:
db.driver=${db.driver}
db.url=${db.url}
username=${username}
password=${password}
Your servlet-context.xml file
<context:property-placeholder location="classpath:your-property-file.properties" />
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>${db.driver}</value></property>
<property name="url"><value>${db.url}</value></property>
<property name="username"><value>${username}</value></property>
<property name="password"><value>${password}</value></property>
</bean>
In your pom.xml
<resources>
...
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
...
</resources>
I haven't tried it, but as per this maven wiki page, you should be able to refer to properties in settings.xml using settings. prefix. So ${settings.servers.server.username} should ideally return the username in settings.xml.

Resources