Home > Mobile >  Jenkinsfile for different operating system like Windows and Linux
Jenkinsfile for different operating system like Windows and Linux

Time:06-04

I have a Jenkinsfile to create a pipeline. If this pipeline should be executed on different operating system like Linux and Windows, which is the best approach to manage this situation?

I mean, do I need to create two different Jenkinsfile? One for Windows and another one for Linux in order to manage the different commands/shell operating systems? Thanks in advance

CodePudding user response:

There is a isUnix() function that will return TRUE if the node that you are running on is a Unix like OS (Unix/MacOS/Linux), or FALSE if it is running on Windows. You should be able to implement a if check

script {
    if (isUnix()) {
       //Linux Environment
       sh ./script.sh
     }
     else {
       //Windows Environment
       bat batchfile.bat
     }
 }
  • Related