I am new to jenkin, I have created a jenkinFile to build a war and copy it to a remote machine on tomcat server based on the following tutorial:
https://thenucleargeeks.com/2020/05/31/declarative-jenkins-pipeline-to-deploy-java-web-application/
Please find below jenkinFile which i have created:
#!/usr/bin/env groovy
pipeline {
environment {
NAME = readMavenPom().getArtifactId()
}
agent any
options {
timeout(time: 1, unit: 'HOURS')
buildDiscarder(logRotator(daysToKeepStr: '10', numToKeepStr: '5', artifactNumToKeepStr: '2'))
}
stages {
stage("Git Checkout"){
steps{
git branch: 'develop',
credentialsId: 'jenkins', url: 'https://gitlab.gov/ih/ih-por.git'
}
}
stage('Maven build') {
steps {
sh "mvn clean package"
sh "mv target/*.war target/UI.war"
}
}
stage("deploy-dev"){
steps{
sshagent(['user-id-tomcat-deployment']) {
sh """
scp -o StrictHostKeyChecking=no target/UI.war
root@192.168.1.000:/opt/tomcat/webapps/
ssh root@192.168.1.000 /opt/tomcat/bin/shutdown.sh
ssh root@192.168.1.000 /opt/tomcat/bin/startup.sh
"""
}
}
}
}
}
I have also created added the private key on my jenkin server.
However when I build the project on jenkins the following error is displayed by ssh agent:
[Pipeline] { (deploy-dev)
[Pipeline] sshagent (hide)
[ssh-agent] Using credentials root (This defines the credential to login remote server where tomcat is installed for deployment purpose)
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent] Exec ssh-agent (binary ssh-agent on a remote machine)
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-r2GnAq9cX2F8/agent.37244
SSH_AGENT_PID=37247
Running ssh-add (command line suppressed)
Identity added: /var/lib/jenkins/workspace/InfoHighway/portal-ui-deploy@tmp/private_key_6145932096571627059.key (root@localhost.localdomain)
[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
+ scp -o StrictHostKeyChecking=no target/portalUI.war
usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user@]host1:]file1 ... [[user@]host2:]file2
[Pipeline] }
$ ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 37247 killed;
[ssh-agent] Stopped.
[Pipeline] // sshagent
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE
Any idea what I am doing wrong please?