I'm a newbie on Jenkins Pipelines. I wrote this small Groovy script from pulling from git and compiling.
node('master') {
def workspace = pwd()
stage 'Git pull'
git branch: 'develop',
credentialsId: 'Cred_xxxx',
url: 'https://xxxx/yyyy.git'
stage 'Builing'
def mvnHome = tool name: 'Maven3', type: 'hudson.tasks.Maven$MavenInstallation'
sh "cd ${workspace}/tlt/; ${mvnHome}/bin/mvn install -Pdevelopment"
sh "cd ${workspace}"
}
Now I would like to deploy on Tomcat7 the file tlt/target/tlt.war
.
The previous approach was to fill the "Deploy war/ear to container" plugin.
Now, I have no idea how to do this with Groovy.
Thanks
Riccardo
When using Jenkinsfile you need to copy the war yourself to the tomcat using groovy script.
If Tomcat is on the same server you can do just:
sh 'cp tlt/target/tlt.war TOMCAT_DIRECTORY/webapps/'
If on other host you would need to do scp
and configure user and password:
sshagent(['CREDENTIALS_ID']) {
sh 'scp tlt/target/tlt.war some-remote-host:/LOCATION/TOMCAT/webapps/'
}
where CREDENTIALS_ID
is the ID take from the URL of credentials that you need to add in jenkins credentials page (it is in the url, a string like 4644a37d-4291-474e-813b-14b58bef1125).
Another solution, more easy is to create a Job with only the task "Deploy war/ear to container" and to call it through the "build" command in Groovy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With