Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-70076

How to pass parameters to remote script with SSH steps plugin

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • ssh-steps-plugin
    • None

      I'm running into issues trying to pass params to sshScript - found this SO with the same problem but the OP never got a response.

      How should one do this?

      https://stackoverflow.com/questions/64055072/how-to-pass-paramaters-to-remote-script-in-a-jenkins-pipeline/74437699#74437699

          [JENKINS-70076] How to pass parameters to remote script with SSH steps plugin

          Markus Winter added a comment - - edited

          You can use 2 scripts

          The first calls the second with the parameters. This is not nice when you need to pass credentials as you will get warnings about string interpolation done by jenkins, but there is no other way I think at the moment

          writeFile file: wrapper.sh, text: """
          chmod +x scripts.sh
          ./scripts.sh ${Username}
          """ 
          sshPut remote: remote, from: './script.sh', into: '.'
          sshPut remote: remote, from: './wrapper.sh', into: '.'
          sshScript remote: remote, script: "wrapper.sh"

          You could also use

          sshCommand 
          

          to call the script that you put before. Here you can pass parameters

          Markus Winter added a comment - - edited You can use 2 scripts The first calls the second with the parameters. This is not nice when you need to pass credentials as you will get warnings about string interpolation done by jenkins, but there is no other way I think at the moment writeFile file: wrapper.sh, text: """ chmod +x scripts.sh ./scripts.sh ${Username} """ sshPut remote: remote, from: './script.sh' , into: '.' sshPut remote: remote, from: './wrapper.sh' , into: '.' sshScript remote: remote, script: "wrapper.sh" You could also use sshCommand to call the script that you put before. Here you can pass parameters

          Thanks mawinter69 everything was fine after using `sshCommand` with a password (caveat: I had to chmod first with sshCommand before running the script with sshCommand in order to be able to run the script I placed on remote with sshPut)

          Matthew Oldach added a comment - Thanks mawinter69 everything was fine after using `sshCommand` with a password (caveat: I had to chmod first with sshCommand before running the script with sshCommand in order to be able to run the script I placed on remote with sshPut)

            Unassigned Unassigned
            oldachm Matthew Oldach
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: