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

groovy CLI command cannot be used with stdin via SSH

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • cli, core
    • None

      There's no reason this shouldn't be possible. Let's allow groovy command use via SSH CLI.

          [JENKINS-41765] groovy CLI command cannot be used with stdin via SSH

          Code changed in jenkins
          User: Daniel Beck
          Path:
          core/src/main/java/hudson/cli/GroovyCommand.java
          http://jenkins-ci.org/commit/jenkins/0d3d6b65bf134ba01d67908db63212dc54aa1c58
          Log:
          [FIX JENKINS-41765] Allow groovy CLI command via SSH

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Beck Path: core/src/main/java/hudson/cli/GroovyCommand.java http://jenkins-ci.org/commit/jenkins/0d3d6b65bf134ba01d67908db63212dc54aa1c58 Log: [FIX JENKINS-41765] Allow groovy CLI command via SSH

          Daniel Beck added a comment -

          Fixed in 2.46

          Daniel Beck added a comment - Fixed in 2.46

          Dorian Daumiller added a comment - - edited

          This doesn't seem to work.

          When trying to execute a groovy command over the ssh method, Jenkins complains about me wanting to use the -remoting mode:

          java -jar ./jenkins-cli.jar -ssh -user **** -i **** -s http://myserver:1234/jenkins/testing/ groovy command.groovy 
          ERROR: This command is requesting the deprecated -remoting mode. See https://jenkins.io/redirect/cli-command-requires-channel

          The URL btw points to the not yet quite complete CLI documentation (which mentions that some commands wouldn't work, but not which ones...)

          The command was a simple println

          Dorian Daumiller added a comment - - edited This doesn't seem to work. When trying to execute a groovy command over the ssh method, Jenkins complains about me wanting to use the -remoting mode: java -jar ./jenkins-cli.jar -ssh -user **** -i **** -s http: //myserver:1234/jenkins/testing/ groovy command.groovy ERROR: This command is requesting the deprecated -remoting mode. See https: //jenkins.io/redirect/cli-command-requires-channel The URL btw points to the not yet quite complete CLI documentation (which mentions that some commands wouldn't work, but not which ones...) The command was a simple println

          Same when I try groovy from standard-in
          java -jar ./jenkins-cli.jar -ssh -user **** -i **** -s http://myserver:1234/jenkins/testing/ groovy println 'hello world'ERROR: This command is requesting the deprecated -remoting mode. See https://jenkins.io/redirect/cli-command-requires-channel

          Dorian Daumiller added a comment - Same when I try groovy from standard-in java -jar ./jenkins-cli.jar -ssh -user **** -i **** -s http://myserver:1234/jenkins/testing/ groovy println 'hello world'ERROR: This command is requesting the deprecated -remoting mode. See https://jenkins.io/redirect/cli-command-requires-channel

          Daniel Beck added a comment -

          When trying to execute a groovy command over the ssh method, Jenkins complains about me wanting to use the -remoting mode

          Only the remoting mode can access local files.

          which mentions that some commands wouldn't work, but not which ones

          Basically a direct consequence of extensibility, there can never be a complete list.

          Same when I try groovy from standard-in

          That's not stdin. stdin is when you use a pipe or input redirection. What you're doing isn't supported by the documentation at all (you're telling it to read from a file called "println"):

          java -jar jenkins-cli.jar -s … groovy [SCRIPT] [ARGUMENTS ...]
          SCRIPT : Script to be executed. File, URL or '=' to represent stdin.

           

          Daniel Beck added a comment - When trying to execute a groovy command over the ssh method, Jenkins complains about me wanting to use the -remoting mode Only the remoting mode can access local files. which mentions that some commands wouldn't work, but not which ones Basically a direct consequence of extensibility, there can never be a complete list. Same when I try groovy from standard-in That's not stdin. stdin is when you use a pipe or input redirection. What you're doing isn't supported by the documentation at all (you're telling it to read from a file called "println"): java -jar jenkins-cli.jar -s … groovy [SCRIPT] [ARGUMENTS ...] SCRIPT : Script to be executed. File, URL or '=' to represent stdin.  

          Understood.

          writing the command into a command.groovy and then piping it into the groovy CLI command worked

          This pipeline

          writeFile file: 'cmd.groovy', text: getCommandText()
          def getCommandText() {
          '''
          println 'HelloWorld'
          '''
          }
          sh 'cat cmd.groovy | java -jar ./jenkins-cli.jar -ssh -user * -i * -s http://serv:14/ groovy ='
          

          looks like this

          Running shell script
          + cat cmd.groovy | java -jar ./jenkins-cli.jar -ssh -user **** -i **** -s http://serv:14/ groovy =
          HelloWorld
          

          Thanks for clarifying

          Dorian Daumiller added a comment - Understood. writing the command into a command.groovy and then piping it into the groovy CLI command worked This pipeline writeFile file: 'cmd.groovy' , text: getCommandText() def getCommandText() { ''' println 'HelloWorld' ''' } sh 'cat cmd.groovy | java -jar ./jenkins-cli.jar -ssh -user * -i * -s http: //serv:14/ groovy =' looks like this Running shell script + cat cmd.groovy | java -jar ./jenkins-cli.jar -ssh -user **** -i **** -s http: //serv:14/ groovy = HelloWorld Thanks for clarifying

            danielbeck Daniel Beck
            danielbeck Daniel Beck
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: