-1

I am trying to use VSTS to deploy a zip file to a Linux VM in Azure. I am using an SSH task to run the command:

sudo unzip -ju /home/$USER/release/deployfile-1.6.zip "*.war" -d "/opt/tomee/webapps/"

That command works. I don't want to change the filename each time it changes, though. I tried using a variable name:

sudo unzip -ju /home/$USER/release/$filename "*.war" -d "/opt/tomee/webapps/"

And I tried using a wildcard:

cd "/home/$USER/release/"
sudo unzip -ju '*.zip' "*.war" -d "/opt/tomee/webapps/"

(the above is supposed to be star.zip and star.war) Neither of those worked, and having little familiarity with Linux, I haven't been able to figure out a syntax that works.

Could someone please advise? Thank you.

jww
  • 97,681
  • 90
  • 411
  • 885
user1165224
  • 97
  • 1
  • 10
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Apr 02 '18 at 18:10
  • `sudo unzip -ju /home/$USER/release/*.zip "*.war" "/opt/tomee/webapps/"` should work, I imagine. Which is virtually the same as your last attempt, however your last attempt fails because you use single quotes around your wildcard turning it into a string literal. Use double quotes, or no quotes at all. – JNevill Apr 02 '18 at 18:22
  • Possible duplicate of [Difference between single and double quotes in Bash](https://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash) – JNevill Apr 02 '18 at 18:24
  • @jww I am executing the commands through the release pipeline in VSTS, which I've seen often modifies the commands with variables and such. Because I'm trying to do this through a deployment pipeline, it seemed a reasonable place to ask the question. Maybe I'm mistaken. – user1165224 Apr 02 '18 at 20:18
  • @JNevil Thank you for those suggestions. I tried with and without double quotes and both times the deployment locked up because the command was waiting for me to respond if I wanted to overwrite files. After several tries I ended up with `sudo unzip -jo "/home/$USER/release/$(filename)" "*.war" -d "/opt/tomee/webapps/"` – user1165224 Apr 02 '18 at 21:00
  • Perfect. The -o options is write on for unattended overwrites. I'm glad you got it working! – JNevill Apr 02 '18 at 21:05

1 Answers1

0

Based on @JNevill comments, I made another attempt at using a variable for the filename. I also changed the u parameter to an o to automatically overwrite files. The final command syntax is:

sudo unzip -jo "/home/$USER/release/$(filename)" "*.war" -d "/opt/tomee/webapps/"

When the command is executed on the remote VM it becomes:

sudo unzip -jo "/home/$USER/release/deployfile-1.6.zip" "*.war" -d "/opt/tomee/webapps/"

The war files were successfully deployed to the VM.

user1165224
  • 97
  • 1
  • 10