In pipeline stages where a node could be windows or unix, it would be useful to have a generic command step for commands that are the same in batch or shell instead of requiring a conditional isUnix() block or custom function. Example use cases would be calling ruby or python scripts, or running other programs that have the same CLI on multiple platforms like doxygen, cmake etc.

      My current workaround is:

      def command(command) {
        if (isUnix()) {
          sh command
        } else {
          bat command
        }
      }

      Or to reduce the number of isUnix calls and outputs in Blue Ocean or Stage View, have the isUnix bool an argument for the command method.

      This is a simple workaround but somewhat annoying to need in either every jenkinsfile, or to need a global pipeline library for.

      Example syntax:

      command "echo Hello world!"

       Not sure if "command" is an appropriate name but could really be anything.

      It may also be helpful to some to be able to call specific programs/shells etc with arguments which could use a named argument form:

      command command: "/bin/bash", arguments: "cat example.txt"
      command command: "/path/to/ruby", arguments: "my-script.rb"

      or with arguments passed as an array which is seen in other applications:

      command command: "/bin/bash", arguments: ["cat", "example.txt"]

          [JENKINS-44991] Add cross-platform command step

          Chris Wright created issue -
          Chris Wright made changes -
          Component/s New: workflow-durable-task-step-plugin [ 21715 ]
          Component/s Original: workflow-basic-steps-plugin [ 21712 ]
          Jesse Glick made changes -
          Link New: This issue duplicates JENKINS-26169 [ JENKINS-26169 ]
          Jesse Glick made changes -
          Link New: This issue duplicates JENKINS-44231 [ JENKINS-44231 ]
          Jesse Glick made changes -
          Resolution New: Duplicate [ 3 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]
          Mark Waite made changes -
          Comment [ Hey everyone!

          I just came across this link and wanted to share my thoughts and knowledge on this topic. The idea of adding a cross-platform command step in pipeline stages sounds really useful and practical. It would definitely simplify the process of executing commands that are the same in both batch and shell environments, eliminating the need for conditional blocks or custom functions based on the platform.

          The current workaround mentioned by the author, using the command method with the isUnix() check, seems like a reasonable solution, but it can be a bit cumbersome to include it in every Jenkinsfile or rely on a global pipeline library. Having a built-in cross-platform command step would greatly improve the workflow and reduce the need for repetitive code.

          I also like the suggestion of allowing specific programs or shells to be called with arguments, using a named argument form or passing arguments as an array. This flexibility would further enhance the usability and versatility of the command step, like this web: https://andersenlab.com/services/cross-platform-development

          Overall, I think implementing a cross-platform command step would be a valuable addition to Jenkins, making pipeline development more streamlined and efficient. ]

            Unassigned Unassigned
            inkychris Chris Wright
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: