简体   繁体   中英

How to run a jenkins pre-build step that depends upon the jenkins slave OS?

In my company, jenkins is configured with one Windows slave and (to come soon) one Mac slave. we want to have a Glassfish domain started as pre-build step, and domain stopped as post-build.

From what I understand, I have to run a "windows batch file pre-build step" on Windows, and a "shell script pre-build step" on Mac.

Can I put both in pre-build steps ? Or should I use an other solution (and if so, which one) ?

You cannot put both in the same job. When the job runs on Mac slave, the "windows batch" will fail. When the job runs on Windows slave, the "shell" will fail.

Why are you trying to add both? I understand that you need the relevant pre-build step, but why are you trying to make the job generic to be executed on either Mac or Windows? Usually running a Mac slave serves a specific purpose (such as doing an Xcode iOS build that cannot be done on a Window), and you restrict that job to run only on Mac slave

If you really need the ability to run either Windows or Mac shell, then you should have a look at XShell plugin
https://wiki.jenkins-ci.org/display/JENKINS/XShell+Plugin

It allows you to execute a "shell" step, on either Windows shell or Mac shell. The plugin will take care of calling the correct shell, and will even do the file separator conversion for you (it will use \\ for Windows, and / for Linux/Mac shell), but the commands you put there must be executable in both shells (ie it will not translate rm into del for you). The Plugin page gives an example how you can "wrap" the commands into a batch and shell file.

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