How do I run a different Shell interpreter in a Pipeline Script?

Article ID:215171038
1 minute readKnowledge base

Issue

  • Can I run a ksh script in a pipeline step?

  • Can I run a perl script in a pipeline step?

Environment

  • CloudBees Jenkins Enterprise

Resolution

By default, the system default shell will be run. In a Shell Step, multiple lines are accepted. It is therefore possible to use an interpreter selector such as !/bin/ksh or !/usr/bin/perl.

KSH Example:

node {
    sh "#!/bin/ksh \n" +
       "echo \"Hello from \$SHELL\""
}

Perl Example:

node {
    sh "#!/usr/bin/perl \n" +
       "print \"Hello from \$SHELL\";"
}
This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.