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

groovy CLI command cannot be used with stdin via SSH

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved (View Workflow)
    • Minor
    • Resolution: Fixed
    • cli, core
    • None

    Description

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

      Attachments

        Issue Links

          Activity

            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_issue_link 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
            danielbeck Daniel Beck added a comment -

            Fixed in 2.46

            danielbeck Daniel Beck added a comment - Fixed in 2.46
            ddaumiller 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

            ddaumiller 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

            ddaumiller 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
            danielbeck 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.

             

            danielbeck 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

            ddaumiller 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

            People

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

              Dates

                Created:
                Updated:
                Resolved: