简体   繁体   中英

How to copy a shell script to created job in jenkins using job dsl plugin?

I have some shell script as like below

echo $BUILD_NUMBER
echo $GIT_BRANCH
echo $SUNNY

How to copy the snippet to created job using dsl script? I know we can achieve it by shell(readFileFromWorkspace('build.sh'))

But is there anyway copy the script using dsl script instead of providing using a .sh file?

There are three ways to configure a shell step.

  1. you can use a script from the seed job's workspace as in your example

     job('example') { steps { shell(readFileFromWorkspace('build.sh')) } } 
  2. you can use an inline script

     job('example') { steps { shell('''echo $BUILD_NUMBER echo $GIT_BRANCH echo $SUNNY''') } } 
  3. you can call a script in the generated job's workspace

     job('example') { steps { shell('./build.sh') } } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM