Created
October 15, 2014 07:11
-
-
Save vegaasen/6f36bb9e23a823f0fedf to your computer and use it in GitHub Desktop.
Simple maven deployer to be used within Jenkins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| <modelVersion>4.0.0</modelVersion> | |
| <groupId>com.vegaasen.app</groupId> | |
| <artifactId>app-maven-deployer-local</artifactId> | |
| <version>1.0-SNAPSHOT</version> | |
| <name>cool-app-maven-deployer</name> | |
| <description> | |
| This pom-file uses the maven-antrun-plugin to be able to execute unix-commands within a pom.xml. | |
| See these links for more references: | |
| -http://maven.apache.org/plugins/maven-antrun-plugin/index.html | |
| -http://maven.apache.org/ant-tasks/index.html | |
| -http://ant.apache.org/manual/Tasks/ | |
| Please note that if you are to use this with Jenkins CI - here are some useful information regarding Environment | |
| variables: | |
| -https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project | |
| Same goes for Hudson CI: | |
| -http://wiki.hudson-ci.org/display/HUDSON/Building+a+software+project | |
| Allowed POM-parameters (specified as e.g: -DuserName=****): | |
| -JOB_NAME | |
| -userName | |
| -userPassword | |
| </description> | |
| <packaging>pom</packaging> | |
| <developers> | |
| <developer> | |
| <name>Vegard Aasen</name> | |
| <email>[email protected]</email> | |
| <organization>me.</organization> | |
| <roles> | |
| <role>Retard</role> | |
| </roles> | |
| </developer> | |
| </developers> | |
| <build> | |
| <plugins> | |
| <plugin> | |
| <groupId>org.apache.maven.plugins</groupId> | |
| <artifactId>maven-antrun-plugin</artifactId> | |
| <version>1.7</version> | |
| <executions> | |
| <execution> | |
| <phase>compile</phase> | |
| <configuration> | |
| <tasks> | |
| <echo message="Trying to find the latest release ..." level="info"/> | |
| <exec executable="bash" outputproperty="deploymentUrl"> | |
| <arg value="-c"/> | |
| <arg value="grep --text --extended-regexp --only-matching --max-count=1 'http://.*?app-web.*?app-web-.*?.war' /home/<you>/.jenkins/jobs/${JOB_NAME}/lastSuccessful/log"/> | |
| </exec> | |
| <echo message="Using ${deploymentUrl} as the deployment url ..." level="info"/> | |
| <echo message="Starting deployment on Server #1 ..." level="info"/> | |
| <sshexec | |
| timeout="${antrun.sshexec.timeout}" | |
| failonerror="false" | |
| trust="true" | |
| host="${antrun.sshexec.host.s1}" | |
| username="${userName}" | |
| password="${userPassword}" | |
| port="22" | |
| command="bash -c 'source .bashrc;touch .bashrc;app.sh stop;svn up;chmod 744 $HOME/scripts/*.sh;find $HOME/scripts -type f -name *.sh -exec dos2unix {} +;PATH=$PATH:$HOME/scripts;app.sh release ${deploymentUrl};'"/> | |
| <!-- | |
| <echo message="Starting deployment on Server #2 ..."/> | |
| <sshexec | |
| timeout="${antrun.sshexec.timeout}" | |
| failonerror="false" | |
| trust="true" | |
| host="${antrun.sshexec.host.s2}" | |
| username="${userName}" | |
| password="${userPassword}" | |
| port="22" | |
| command="MISSING"/> | |
| --> | |
| <echo message="Completed with the release ..." level="info"/> | |
| </tasks> | |
| </configuration> | |
| <goals> | |
| <goal>run</goal> | |
| </goals> | |
| </execution> | |
| </executions> | |
| <dependencies> | |
| <dependency> | |
| <groupId>org.apache.ant</groupId> | |
| <artifactId>ant-jsch</artifactId> | |
| <version>${maven.plugin.antjsch}</version> | |
| </dependency> | |
| </dependencies> | |
| </plugin> | |
| </plugins> | |
| </build> | |
| <properties> | |
| <antrun.sshexec.timeout>600000</antrun.sshexec.timeout> | |
| <maven.plugin.antjsch>1.8.4</maven.plugin.antjsch> | |
| <antrun.sshexec.host.s1>0.0.0.0</antrun.sshexec.host.s1> | |
| </properties> | |
| </project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment