My problem is that the packaged war
file is not deployed from GitHub to Azure using Travis-CI correctly - the entire repository with the generated files are just copy-pasted. Here is what I do:
My approach:
I follow the Travis tutorial about Azure web app deployment and try to achieve the same in the minimal form. My goal is to assemble a war
file and deploy it to Azure web app with Tomcat 8.0 container.
My project has the following .travis.yml
configuration (I have omitted Java-8 definition, Sonar add-ons, and Coveralls after_success script for the sake of brevity):
script:
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar
deploy:
provider: azure_web_apps
skip_cleanup: true
I use AZURE_WA_USERNAME
, AZURE_WA_PASSWORD
and AZURE_WA_SITE
environment variables.
I follow the standard Maven directory structure. The output directory is the standard /target
. Thus, on the Travis is generated into:
/home/travis/build/MY_USERNAME/MY_WEBAPP/target/MY_WEBAPP.war
Where MY_USERNAME
is the GitHub login name and MY_WEBAPP
is the name of my application. The deployment looks fine at the first sight (I skipped similar lines):
Deploying application
[detached HEAD 9fd0ce7] Skip Cleanup Commit
54 files changed, 128 insertions(+)
create mode 100644 target/MY_WEBAPP-0.0.1-SNAPSHOT.war
create mode 100644 target/MY_WEBAPP-0.0.1-SNAPSHOT.war.original
create mode 100644 target/MY_WEBAPP-0.0.1-SNAPSHOT/WEB-INF/classes/... <- Skipped 3 lines
create mode 100644 target/MY_WEBAPP-0.0.1-SNAPSHOT/WEB-INF/lib/... <- Skipped 20+ lines
... irrelevant ... <- Skipped 7 lines
Done. Your build exited with 0.
What is wrong and how it should be correct:
If I upload manually the war
file via FTP(S) to the Azure directory /site/wwwroot/webapps
, it's unpacked and deployed within a minute and works well.
Unlike the manual copy, Travis takes all the content and copy-paste it literally into the Azure webapp resulting in the mess like:
The war
file hasn't been uploaded into the webapps
folder. The newly created Azure webapp contains site/wwwroot/webapps/ROOT
folder and is needed to upload the war
file on the ROOT
folder level. I have expected Travis would perform "smarter" behavior.
Question:
How to deploy to Azure from GitHub using Travis-CI correctly? I bet I miss something that isn't documented.
My workaround-attempts:
I have tried to fix the thing in several ways (none of them has worked). I consider all of them dirty:
I tried to specify what to deploy in .travis.yml
(no effect, everything is copied still):
file_glob: true
file: "/home/travis/build/MY_USERNAME/MY_WEBAPP/target/MY_WEBAPP*.war"
An ugly bruteforce: Change the output directory from /target
to /webapp
resultin to override the destination folder in Azure upon deployment in the <build>
section of 'pom.xml`:
<directory>/webapps</directory>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>MY_WEBAPP</warName>
<outputDirectory>/webapps</outputDirectory>
</configuration>
</plugin>
Rename the output folder to webapps
in .travis.yml
:
after_success:
- bash mv /home/travis/build/MY_USERNAME/MY_WEBAPP/target/ /home/travis/build/MY_USERNAME/MY_WEBAPP/webapps/
/bin/mv: /bin/mv: cannot execute binary file
I have resolved the issue with uploading deployment scripts:
.deployment
[config]
command=deployment.cmd
deployment.cmd
@echo off
echo Azure: Deploying site
echo Azure: Removing the current war file
del %DEPLOYMENT_TARGET%\webapps\MY_WEBAPP.war /S /Q
echo Azure: Removing the current webapp folder
rmdir %DEPLOYMENT_TARGET%\webapps\MY_WEBAPP /S /Q
echo Azure: Copying war to the webapps folder
xcopy %DEPLOYMENT_TARGET%\..\repository\target\MY_WEBAPP.war %DEPLOYMENT_TARGET%\webapps /Y /s