Get buildid in teamcity - teamcity

I would like to get the buildId (such as #2594) of the current teamcity job as an input to my script. I tried:
if [ $? != 0 ]; then
python store_test_artifacts.py --buildId %system.build.number%
fi
But this leads to the error:
There are no compatible agents which can run this build.
and
Implicit requirements:
system.teamcity.build.id defined in Build step: Setup
How can I pass the buildID shown in teamcity to my script?

It's available as a environment variable:
echo $BUILD_NUMBER

Related

what is command "mvnyjp" in maven for? when to use it?

there are three commands in maven/bin:
mvn
mvnDebug
mvnyjp
I just find nothing about "mvnyjp".
How and when to use it?
Its a shell script intended to be used with Yourkit profiler.
Used to profile maven build process.
It's a script file and therefore readable:
# -----------------------------------------------------------------------------
# Apache Maven YourKit Profiler Startup Script
#
# Environment Variable Prerequisites
#
# JAVA_HOME Must point at your Java Development Kit installation.
# MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
# MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
# -----------------------------------------------------------------------------
if [ ! -f "$YJPLIB" ]; then
echo "Error: Unable to autodetect the YJP library location. Please set YJPLIB variable" >&2
exit 1
fi
env MAVEN_OPTS="-agentpath:$YJPLIB=onexit=snapshot,onexit=memory,tracing,onlylocal $MAVEN_OPTS" "`dirname "$0"`/mvn" "$#"
So it seems like it's only of interest, if you are using the YourKit Profiler.

How to run Maven / JVM (e.g. Appium + Saucelabs / Selenium + Browserstack) Test Automation on Bitrise

Is it possible to run Java based test automation suite on Bitrise CI/CD?
Functionalities which I will be looking at:
- Maven Runtime
- String Parameters passing
- Cucumber-JVM
- Connectivity to Cloud devices provider like Browserstack(web) / Saucelabs(mobile)
Also, what kind of job will we need to set-up on Bitrise, for this purpose
Thanks
This can be achieved by using a Script step which calls a script inside your repository: (Path is relative to your repo)
Script Step:
#!/usr/bin/env bash
set -ex
bash ./scripts/bitrise/test_controller.sh
Inside the test_controller.sh we have logic which controls the other bash scripts to execute (can use ruby as well), which will we will then run maven in:
test_controller.sh
#!/usr/bin/env bash
set -ex
if [[ "$SHOULD_RUN_SPECIFIC_TESTS" == "false" && "$SHOULD_RUN_RELEASE_TESTS" == "false" ]]; then
if [[ $BITRISE_TRIGGERED_WORKFLOW_TITLE == "iOS-Appium" ]]; then
echo "=> Executing run_develop_ios_tests.sh"
bash ./scripts/bitrise/ios/run_develop_ios_tests.sh
exit 0
elif [[ $BITRISE_TRIGGERED_WORKFLOW_TITLE == "Android-Appium" ]]; then
echo "=> Executing run_develop_android_tests.sh"
bash ./scripts/bitrise/android/run_develop_android_tests.sh
exit 0
fi
fi
If we don't want to run specific tests, and not release, and the workflow that triggered this run is iOS-Appium, then we run execute run_develop_ios_tests.sh:
run_develop_ios_tests.sh
#!/usr/bin/env bash
set -ex
mvn clean test \
-DplatformName=IOS \
-Dsurefire.suiteXmlFiles="${XML_FILES}" \
-DIOS_DEVICE_NAME="${IOS_DEVICE_NAME}" \
-DIOS_PLATFORM_VERSION="${IOS_PLATFORM_VERSION}" \
-DSAUCE_USERNAME="${SAUCE_USERNAME}" \
-DSAUCE_ACCESS_KEY="${SAUCE_ACCESS_KEY}"
The logic inside the test controller, is driven by env variables -- and so are the string params which guide our mvn clean test command.
Since we connect to SauceLabs remotely, we do not need any special agent for this. Just JDK and Maven, which are pre-installed.
Bitrise definitely provides these functionality and can auto configure or recommend some solution while you're doing the project setup. If you'd need any help/guidance along the process contact the Bitrise support (via the onsite chat or email), they can help you with your specific setup :)

The shell script called inside 'Execute Shell' build step fails, but Jenkins build is marked as passed

I am calling a shell script with some parameters within 'Execute Shell' build step in Jenkins.
./shell_1.sh "$Param1" "$Param2" "$Param3"
This shell script downloads puppet modules, sets up the directories and then finally calls a puppet script.
puppet apply ${WORKSPACE}/scripts/puppet/sample.pp
The problem here is that Jenkins console shows the error from the puppet script and then finish with Success status.
Following are the last 3 lines from Jenkins console:
06:46:44 [1;31mError: /Stage[main]/Main/Deployit_environment[Environments/Build/Test/UAT/UAT-env]: Could not evaluate: cannot send request to deployit server 404/Not Found:Repository entity [Infrastructure/Build/Test/UAT/server_123/test-sample-service] not found[0m
06:46:44 [mNotice: Applied catalog in 1.82 seconds[0m
06:46:45 Finished: SUCCESS
I want the Jenkins job to fail if there is any error in puppet script.
I tried calling shell script with -xe option. But didn't work.
Thanks in advance.
The Jenkins Build step checks if the error code of the script is 0. If it has another value it will fail the build.
You can use special shell variable called $? to get the exit status of the previously executed command. To print $? variable use the echo command:
echo $?

How to find if a Job fails in jenkins

I am really new to Jenkins and shell scripts, I just want to know if I have a set of commands which are configured in a build, is there any simple way to know if the job failed or the set of commands terminated to due some reason?
For example as under configure job if we have a set of shell commands as below can i embed them in on if statement as below :
if [ ${jenkinsHome}/doThis.sh > andThis.sh
${jenkinsHome}/nowDOThis.sh > ${workpsace}/commit.sh
${workpsace}/test.sh test
]
then
echo "build passed"
else
echo "failed"
fi
Can i do something like the above. please suggest.

Executing Maven task from shell script and getting error codes

I'm executing a Maven deploy task from a bash script however even if the Maven task fails the script will continue and complete without errors.
I have tried the -e flag but that causes the deploy to fail. I also tried the following (pseudo code)
result_code= mvn deploy
if [$result_code -gt 0];then
exit 1
Any suggestions how i can identify if the deploy was successful?
result_code=mvn deploy is not the way to get return status
you can try e.g. :
#!/bin/bash
mvn deploy
STATUS=$?
if [ $STATUS -eq 0 ]; then
echo "Deployment Successful"
else
echo "Deployment Failed"
fi
In addition if anyone using Windows 10, here is the example which I use:
mvn deploy
if not %ERROR_CODE%==0 goto error
echo SUCCESS
goto end
:error
echo FAILED
:end
Just one other possible reason a person's mvn task may return 0 despite failing: be careful about piping the output of maven to other programs. For example, I'm using grcat (which grc is build on top of), which will always return exit code 0;
\mvn compile | grcat ~/conf.mvn
I'm not sure how to retain my nice color coding of the output. There is color_maven.sh out there but that has other issues.

Resources