How do I specify a variable (specifically a file name) in a Bamboo SSH task?

Sean Norman January 27, 2015

I'm trying to create a deploy plan which:

  1. Uploads a shared artifact to a remote server using an SCP task
  2. Executes an SSH task that runs a script on the remote server that takes as its argument the name of the file to install to the app server

I have everything working up until step #2, where I'm stuck trying to find a way to execute the deploy script.

Is there any way that I can refer to the file that was uploaded as part of the SCP task? If not, what good is it to SCP a file if we cannot refer to it in future tasks?

We're using Maven for build & dependency management and each successful build increments the POM number, so the name of the file to deploy isn't static.

 

1 answer

0 votes
Gretchen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2015

The artifact should be what you are copying in an scp task. Getting the name of the artifact in the ssh task looks like it could be tricky though.  

My initial thoughts are to put the name of the artifact in an injection variable.  But again identifying the artifact may be a problem.

I know that you can reference the artifact directory using variables and perhaps what you need to do if your ssh command is not a static value (a batch script name for example) is get a list of the files in your artifact store for that build here: http://your.org/bamboo/browse/${bamboo.planKey}-JOB1/latest/artifact  (assuming your artifacts are created in the JOB1 stage) 

If you were to retrieve that as a rest request you could parse it for the specific artifact you are looking for then put that in an injection variable.  (essentially a variable/value pair in a text file on the filesystem).  

Yes, it is clunky and a hassle to script but it will work.  

All that said we generally have the server we are deploying to run a script to pickup whatever artifact we dump there and deploy from the server side rather than trying to do it from the bamboo host.  It's just easier to do it that way for us.

For example if you have a tomcat war file to deploy, bamboo dumps the artifact in a staging location on the application server, then a cron or windows scheduled task checks the server staging location and if it finds a candidate (*.ear) deploys it.  

You could also use a script on the server that was executed by a script on the bamboo host that would do the same thing.  The difference is that you would be executing a named script "deploy.sh" or "deploy.cmd/bat/whatever" to actually deploy the artifact using wildcards in the script.

Hope this helps.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events