Jenkins pipeline groovy example

In this tutorial, I have written a script groovy using Jenkins pipeline call shell to create a folder and copy. How to Execute shell script from Jenkins groovy script in Pipeline. Now, let’s go to Jenkins pipeline groovy example.

Jenkins Pipeline creates multiple automation jobs with the help of use cases and runs them as a Jenkins pipeline.

You can installed build pipeline plugin on Jenkins server.

Jenkins pipeline groovy example

I will create 3 folder: app1,app-api,app2 and copy war file is app1.war,app-api.war,app2.war

JENKINS_HOME: /var/lib/jenkins
WORKSPACE: /var/lib/jenkins/{JOB_NAME}

Execute shell script from Jenkins groovy script in Pipeline.

node('master') {
stage('Create directory and copy to folder release') {
   artifacts = "app1,app-api,app2"
   targets = artifacts.split(",")
   for (String artifact : targets){
         Warfile = artifact + ".war"
         sh """
              mkdir -p ${JENKINS_HOME}/delivery/${artifact}           
              cp ${WORKSPACE}/${artifact}/target/${Warfile} ${JENKINS_HOME}/delivery/${artifact}/
         """
 }
 }
}

Conclusion

Thought the article, “How to execute a shell script from Jenkins groovy script in Pipeline ” as above. I hope will this your helpful. Thank you for reading DevOpsRoles.com page

, , ,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.