I am running my automation test suite from TeamCity. I need to access the buildId property as I have a situation where I have to construct a file path using this buildId.
I tried using System.getProperty("teamcity.build.id") but it just displays null. How can I access the buildID of the current team city run from my automation code which is written in java.
You can pass it while running the build step, using %build.number%.
https://confluence.jetbrains.com/display/TCD5/Predefined+Properties
Related
All, I have a test suite developed using spock-groovy framework. The output of this is a set of html files. I have a requirement to run this test as part of a docker container on cloud. After the test execution, I would like to get a summary of the test results and also a link of the html files to view the details of these results.
Is there a library already available for parsing the test results for spock? How can I get this done using Java from the app running in the container?
Build tool: gradle.
I created the docker container using the Dockerfile. The entrypoint for this docker container is a shell script which sets required variables and then executes the command gradle clean test....
Few issues I am trying to resolve:
The container is able to execute the tests but I am unable to get the results out of that container. I am trying the approach as mentioned in point 2 below to get the results out of the container.
I have added def cleanupSpec() {....} method where I am trying to send a notification to slack channel. As I see from inside the container, this step is not getting executed. When I run this app locally, I am able to see the notification being sent.
I have just added my cucumber test to an Azure pipeline. After running the pipeline I noticed that my cucumber tests are showing up as runScenario instead of the test name.
If I click on the runScenario and I go to Attachments I do see that it shows my test scenario there.
If I run it in IntelliJ my tests shows up as runScenario []
I've googled a bit but cant seem to find how to fix that. Any idea how to show my test scenario or Feature?
On your Agent job tasks I used Maven.
In the configuration under JUnit Test Results add the path to your Junit result (Should be an .xml file). For me specifically it was under:
$(System.DefaultWorkingDirectory)/<project>/target/cucumber-junitReports/Cucumber.xml
Teamcity Build ID (which is different from BUILD_NUMBER) is used in various URLs. I want to send an email having path of a build's artifacts/ overview etc.
In Java, we can get currently running teamcity build number as follows:
String tc_BuildNumber = System.getenv("BUILD_NUMBER");
This is because TC provides an environment variable namely BUILD_NUMBER.
But unfortunately, there is no environment variable corresponding to BUILD_ID.
TeamCity does provide Configuration parameters (like teamcity.build.id) and System property (like system.teamcity.auth.userId) but I don't know how to access these using Java. I want to read the value of teamCity.build.id jusy like we can read environment variables names mentioned in How to fetch the Value of Teamcity Configuration in java?
Are you executing the java code using a build runner?
If so, then you should be able to pass %system.teamcity.build.id% to the runner, and make it available to your code.
i.e. If you're using the command line runner
java -Dbuild_id=%system.teamcity.build.id%
which you can then access as system arguments
Or if you're using gradle, you can do something like
if (project.hasProperty("teamcity")) {
version = project.teamcity["teamcity.build.id"]
}
and pass 'version' to the java command line.
In maven, you can just access it using:
${teamcity.build.id}
in your pom.xml
(I could do with a little more info about how you're running java to answer this specifically)
I've noticed that lots of people want to know the answer to this question.
Fortunately with the help of comment from #Jayan I was able to do solve my exact problem which was how to get URL for build artifacts.
As mentioned in link https://confluence.jetbrains.com/display/TCD10/Patterns+For+Accessing+Build+Artifacts, by default, TeamCity uses Internal Build ID for the path that can be used to access build artifacts:
/repository/download/BUILD_TYPE_EXT_ID/BUILD_ID:id/ARTIFACT_PATH
Accessing build Id could be difficult in the runtime(That is the reason of this question), but we can also use Build Number to access artifacts
/repository/download/BUILD_TYPE_EXT_ID/BUILD_NUMBER/ARTIFACT_PATH
And as shown in my question build number can be accessed as
String BUILD_NUMBER= System.getenv("BUILD_NUMBER");
and
String BUILD_TYPE_EXT_ID = System.getenv("TEAMCITY_BUILDCONF_NAME");
Yes, but you can create env var with value "%system.teamcity.buildType.id%" and read it in build. After that you can do an api request like:
$APIURL = "${API_BaseUrl}/httpAuth/app/rest/builds/?locator=buildType:${API_BuildType},state:running,count:1"
$APIXML = (Invoke-RestMethod -Headers $API_CredentialsHeader -Credential $API_Credentials -Uri $APIURL -Method GET -ContentType "application/xml" -TimeoutSec 20)
# Here you build id.
$APIXML.builds.build.id
This is PS example. But idea the same. In Java that might be more easy.
A link to a TeamCity build can use build number instead of buildID. But, it requires buildTypeId as well (can be seen in build configuration page URL).
A sample of such link is:
https://buildserver/viewLog.html?buildTypeId=Project_Trunk&buildNumber=46523
Hope this helps someone.
I have a snippet of code that is obtaining an environment variable as follows: System.getenv("MY_VAL")
locally on my windows machine this works fine.
However, on my Jenkins CI Server which is running CentOS I am encountering some issues
I have tried setting the value of MY_VAL through both the envinject plugin as well as the global jenkins settings
If i do a pre-build step to echo the value out, it works fine, however inside my java code this is not being resolved.
How do I get this to be resolved?
You can achieve that by installing EnvInject plugin.
1) After installing check the Prepare an environment for the job option in the job configuration screen. This option will display several field for you to fill.
UPDATE
2) Fill the Script Content area with a command touch env.properties to create the file.
3) Fill the Properties Contentt field with the variables you want to inject inside your recently created env.properties file by doing so. Place one variable per line ex:
VARIABLE1=value
VARIABLE2=value
4) Reference env.properties file you've just created in the file path area.
5) At runtime Jenkins will inject those variables and they will be available to your program.
You need to inject this variable into property.file and then access this from property file. e.g. in execute shell you can define "echo MY_VAL=default > property.file" .. Later in subsequent jobs you can pass through using "Jenkins Parameterized Trigger plugin" where you have option to access parameters from property file.
I am new in load testing.
I want to use gatling for testing. seems to be based on scala ( which runs over JVM)
I want to use some old selenium tests ( java based )
Is it possible to make a java project and run both ?
Well, yes, of course! Just make sure you don't have any library version collision. If that happens, you'll have to isolate in different project/modules.
I believe the easiest option is using Taurus tool which can launch Gatling and Selenium tests using single simple YAML configuration file like:
---
execution:
- executor: gatling
scenario:
script: /path/to/your/GatlingTest.scala
simulation: tests.gatling.BasicSimulation
- executor: "selenium"
scenario:
script: "/path/to/your/SeleniumTest.java"