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

Run PS Script passing parameters

    XMLWordPrintable

Details

    Description

      Hi there,

      I'm trying to run a PS script from a github repo that accept parameters through param() but when I try to pass them with jenkins it fails. I have created a very basic script to prove this. When I call the script withouth parameters it works as espected, but when I try to call it passing one parameter it fails:
      [copla-cli-test0] $ powershell.exe -NonInteractive -ExecutionPolicy Bypass -File C:\Windows\TEMP\jenkins5348470450205503128.ps1
      . : The term 'C:\Windows\Temp\Jenkins\workspace\copla-cli-test0\hellow.ps1 testmessage' is not recognized as the name
      of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
      I have managed to have it working copying the script code in the jenkin's powershell textbox and referencing parameter as $env:parameter but this is not what I need, since we are developing powershell scripts in github I need to call the script something like this:

       

      . "$ENV:WORKSPACE\hellow.ps1 $env:message"
       
      

      I have read something simillar in other Jira issues but didn't helped me much. Is there something I'm missing with powhershell or jenkins? both worlds are relativily new to me.

      Thanks in advance!

       

      Attachments

        Activity

          sunsu alf added a comment -

          Thank you very much Markus, that worked as expected!

          All my attempts were to execute the script as if were on a console, just like this:

          . "$ENV:WORKSPACE\hellow.ps1 -message $env:message"

          Finnally, I was trying to use this other approach I saw in other Jira (https://issues.jenkins.io/browse/JENKINS-60423?focusedCommentId=386979&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-386979) but it made me change my scripts to fit in Jenkins:

          Param ( 
          [string]$workspace = $ENV:WORKSPACE,
          [string]$buildMode = $ENV:BUILD_MODE
          )

           

          Do I have to mark this as resolved or something?

          Best regards,
          /Alf

          sunsu alf added a comment - Thank you very much Markus, that worked as expected! All my attempts were to execute the script as if were on a console, just like this: . "$ENV:WORKSPACE\hellow.ps1 -message $env:message" Finnally, I was trying to use this other approach I saw in other Jira ( https://issues.jenkins.io/browse/JENKINS-60423?focusedCommentId=386979&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-386979 ) but it made me change my scripts to fit in Jenkins: Param ( [string]$workspace = $ENV:WORKSPACE, [string]$buildMode = $ENV:BUILD_MODE )   Do I have to mark this as resolved or something? Best regards, /Alf
          mawinter69 Markus Winter added a comment -

          I think the problem is the quoting. Try
          . "$ENV:WORKSPACE\hellow.ps1" "$env:message"

          mawinter69 Markus Winter added a comment - I think the problem is the quoting. Try . "$ENV:WORKSPACE\hellow.ps1" "$env:message"

          People

            froque Filipe Roque
            sunsu alf
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: