Get Branch Name in Bamboo Deployment Plan - bamboo

How can I get the branch name in a script for a deployment plan in bamboo? The variables listed in the documentation show that we can use bamboo.repository.branch.name, but that doesn't seem to work in a deployment plan.

It works for me do It like this:
It's bamboo.planRepository.branchName not bamboo.repository.branch.name
And it will output this in the log:
I'm using bamboo 5.7, and if it doesn't work, it's probably because of this issue.

Related

How can I write a commit hash to a file using .gitlab-ci before build and deploy

I want to add an endpoint in my server to retrieve the current commit hash in production. I am using .gitlab-ci. I want to do this in the pipeline so that the commit hash is written to a file before "build and deploy". I can read this file on request to return the latest deployed version. Can anyone help me with the steps and examples? Thanks in advance!
I would offer an alternative to this. Use GitLab's environments and deployments features that, in part, considers this exact use case.
In your CI/CD configuration (.gitlab-ci.yml), you can specify an environment: key that will record deployments to your environment(s).
For example:
deploy:
script:
- echo "your deployment script here"
environment:
name: "production"
Now, when this job runs, GitLab will record it as a deployment that can be queried later.
Then you can use the deployments API or the environments API to get the latest deployment information which will include, among other information, the commit hash of the deployment.

Is there a better way to disable/skip a job in a GitLab CI pipeline than commenting everything out?

I have a job in a GitLab CI pipeline that I want to temporarily disable because it is not working. My test suites are running locally but not inside docker, so until I figure that out I want to skip the test job or the test stage.
I tried commenting out the stage, but then I get an error message from the CI validation: test job: chosen stage does not exist; available stages are .pre, build, deploy, .post
So I can simply comment out the entire job, but I was wondering if there was a better way?
Turns out, there is! It's quite at the end of the very thorough documentation of GitLab CI:
https://docs.gitlab.com/ee/ci/jobs/index.html#hide-jobs
Instead of using comments on the job or stage, simply prefix the job name with a dot ..
Example from the official documentation:
.hidden_job:
script:
- run test

Call script after gitlab ci

I have started to work with gitlab ci and I am still new to CI in general. I currently want to call a script after a successful test build of my master branch. This script will notify my server to do a pull, build and restart.
I can not use kubernetes or docker, as the project lead doesn't want to use them.
I can do the scipt and such, but the gitlab ci config documentation is confusing and I cant seem to find an option on how to call the script after it finished.
Stupid of me asking. Its as simple as defining a new stage after the last stage and call the script there.
If you want to do a simple task at the end of a pipeline, try the after_script directive. There is also a before_script counterpart.
Docs at:
https://docs.gitlab.com/ee/ci/yaml/#after_script
https://docs.gitlab.com/ee/ci/yaml/#before_script

How to download the latest log of a Bamboo job?

I want to download the latest log of a Bamboo job programmatically to parse its content and display in a dashboard.
However, Bamboo does not provide a direct link (e.g. with "latest" in URL similar to artifacts download) or to make the Bamboo build log as an artifact.
Someone who has worked around this issue, please share the knowledge.
Check out the REST API offered for bamboo builds: https://docs.atlassian.com/bamboo/REST/6.0.0/
Here's one example from Atlassian's community: https://community.atlassian.com/t5/Answers-Developer-Questions/How-do-you-get-the-build-log-using-REST-API/qaq-p/485212
See "expand": https://docs.atlassian.com/bamboo/REST/6.0.0/#d2e485
... expands build result details on request. Possible values are: changes, metadata, artifacts, comments, labels, jiraIssues, stages, logEntries. stages expand is available only for top level plans. It allows to drill down to job results using stages.stage.results.result. logEntries and testResults are available only for job results
At least as of Bamboo 6.7.1 (and possibly earlier versions), you can issue a request directly for the log using a Script Task, curl, and Bamboo variables:
curl -X GET --user username:password \
"http://localhost:8085/download/${bamboo.buildKey}/build_logs/${bamboo.buildResultKey}.log"
That will give you the textual output of the log.

Maven reporting plugins do not execute if a unit test failure occurs

None of the plugins in the reporting section of Maven execute if there is a unit test failure.
I found that I can set maven.test.failure.ignore=true here - http://jira.codehaus.org/browse/SUREFIRE-247 The problem to this approach is now our hudson builds are successful even if there are unit test failures.
What I would really like to do is set the reporting plugin maven-surefire-report-plugin to run with the build plugins on a phase but I can't get this to work.
Any idea on how to get the Maven reporting plugins to execute if a unit test failure occurs?
Firstly run: mvn test OR mvn install. Then, if the tests fail, please run the following target to generate the reports for the test results executed above: mvn -Dmaven.test.skip=true surefire-report:report
In the link you posted:
With the latest version (2.1.2), I get
a message saying that "There are some
test failure," but I get no reports
anywhere whether or not I specify that
variable, or whether or not I specify
"testFailureIgnore" in the plugin
config. I got the reports fine with
2.0, but not with 2.1.2.
Do you need version 2,1 or can you work with a 2.0 version of Maven?
The error you see with 2.1.2 is because of forkmode settings which you need to perform in the plugin.
set forkmode=never and try it (I susppect there might problem in your useSystemclassloader property).
Otherwise make use of maven-surefire plugin version 2.5 which should definitel work and generate surefire rpeorts even though few test fails.
Please make use of surefire-report:report-only plugin if the reports are already generated after execution.
I had the same issue and it is due to a wrong call to the report plugin.
The correct execution of maven command is: mvn surefire-report:report
This will run the test phase by itself and if it fails it will generate the report anyway.
Check the documentation:
http://maven.apache.org/surefire/maven-surefire-report-plugin/report-mojo.html
Hope this helps!! :D