In this tutorial, I have write script groovy use Jenkins pipeline call shell to create folder and copy. How to Execute shell script from Jenkins groovy script in Pipeline
Jenkins Pipeline create multiple automation jobs with the help of use cases, and run them as a Jenkins pipeline.
You can installed build pipeline plugin on Jenkins server.
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