Tomcat deployment in jenkins pipeline error

26 views Asked by At

Error message: cp /var/lib/jenkins/workspace/myporject/target/petclinic.war /opt/apache-tomcat-9.0.80/webapps/ cp: cannot stat '/opt/apache-tomcat-9.0.80/webapps/petclinic.war': Permission denied

  • I have created a pipeline in jenkins, where built is completed and war file is available.
  • I'm trying to deploy the war file in tomcat server but I'm getting permission denied error.
  • tomcat is up and running.
  • I'm using sudo permission to run this task.

All I want to do is to deploy my war file in tomcat

`stage('Copy WAR to Tomcat') {
            steps {
                script {
                    sh "cp  /var/lib/jenkins/workspace/myporject/target/petclinic.war /opt/apache-tomcat-9.0.80/webapps/ "
                }
            }
        }`

I'm getting permission denied error message in this stage of the pipeline

I have also tried this below steps, still I'm getting this error.

chown -R jenkins /var/lib/jenkins/workspace

when I manually use this command (cp) its working but not working on my pipeline

1

There are 1 answers

2
M B On

I'm assuming permission is denied for the copy destination, not for the file you intend to copy. You will have to give permissions for /opt/apache-tomcat-9.0.80/webapps/ to your Jenkins user. The reason why it works when you do it manually (such as from the host machine terminal) is likely because then you use your own user (not Jenkins user), who has permissions to the opt directory.