Issue with Invoke-RestMethod (powershell)ran thru rundeck

314 views
Skip to first unread message

TAYLOR J HAMMERLING

unread,
Jan 17, 2023, 3:44:14 PM1/17/23
to rundeck...@googlegroups.com

I am having an issue with calling Invoke-RestMethod from one of my scripts.

 

The node is set to use SSH as the default node executor and SCP as the default file copier.  Our Windows nodes have OpenSSH installed and configured on them, with powershell as the default shell when you SSH in.

 

The Job is coded as such

  1. Clone the git repo that contains the script down to the node the script will be run on (Command Step)
  2. Run the script remotely, providing parameters from the keystore as needed (Command Step)

 

                    $secJiraPassword = ConvertTo-SecureString $JiraPassword -AsPlainText -Force

                    $JiraCredentials = New-Object System.Management.Automation.PSCredential ($JiraUsername, $secJiraPassword)

                    $Body = @{

                        "body" = "||*Added to today's commitments; Next Steps:*||`n|$($nextsteps)|`n|#TechEstimateInMinutes:$($techestimate)|"

                        "public" = $false

                    }

 

                    $JsonBody = $Body | ConvertTo-Json

                    $RestParams = @{

                        Method = "Post"

                        Uri = "https://jira.fqdnredacted.com/rest/servicedeskapi/request/$($key)/comment?nofifyUsers=false"

                        Body = $JsonBody

                        ContentType = "application/json"

                        Credential = $JiraCredentials

                        Authentication = "Basic"        

                    }

                    Invoke-RestMethod @RestParams | Out-Null

 

This is the code.  $JiraPassword is passed into the script as a parameter.

When ran this is the error that is returned

 

Invoke-RestMethod : A parameter cannot be found that matches parameter name 'Authentication'.

At C:\tmp\rundeck\Windows\S and O Standup _ Update Jira Tickets\146145\Update_Jira_Tickets.ps1:88

char:39

+ Invoke-RestMethod @RestParams #| Out-Null

+ ~~~~~~~~~~~

+ CategoryInfo : InvalidArgument: (:) [Invoke-RestMethod], ParameterBindingException

+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeRestMetho

dCommand

 

My google foo is failing me.  I would appreciate any help that the great rundeck gurus might be able to provide 😊

 

----------

Taylor Hammerling

WEI/GLBRC IS Support & Operations Manager

    thamm...@wisc.edu

    +1-608-890-1780

    preferred pronouns: he/him/his

    https://open.spotify.com/user/snarfsmojo/playlists

rac...@rundeck.com

unread,
Jan 17, 2023, 5:53:49 PM1/17/23
to rundeck-discuss
Hi Taylor,

Could you provide a job definition example to take a look? 

Probably the issue is related to the script parameters. You can use options as parameters in the following format: ${option.myoption}.

Regards!

TAYLOR J HAMMERLING

unread,
Jan 18, 2023, 9:10:14 AM1/18/23
to rundeck...@googlegroups.com

Gladly!

 

 

- defaultTab: nodes

  description: "This job is manually run each morning after the S and O standup. \

    \ It downloads the excel file which was \ngenerated by 'S and O Standup _ Generate\

    \ Excel Files', parses the excel file and updates the jira tickets\neach technician\

    \ committed to."

  executionEnabled: true

  group: Manually_Run

  id: 08e566e7-5a0c-4797-9e23-b8a86a047be0

  loglevel: INFO

  name: S and O Standup _ Update Jira Tickets

  nodeFilterEditable: false

  nodefilters:

    dispatch:

      excludePrecedence: true

      keepgoing: false

      rankOrder: ascending

      successOnEmptyNodeFilter: false

      threadcount: '1'

    filter: 'name: rdrunner-win.fqdnredacted.com'

  nodesSelectedByDefault: true

  notification:

    onavgduration:

      email:

        recipients: helpdesk@.fqdnredacted.com

        subject: Average Job Duration Exceeded - [${job.project}] ${job.group}/${job.name}

    onfailure:

      email:

        attachLog: true

        attachLogInline: true

        recipients: helpdesk@.fqdnredacted.com

        subject: ${notification.eventStatus} [${job.project}] ${job.group}/${job.name}

  notifyAvgDurationThreshold: 100%

  options:

  - description: This is the Rundeck_Access Gitlab user's READ level Personal Access

      Token

    hidden: true

    name: Rundeck_Access-Gitlab_Personal_Access_Token-READ_API

    secure: true

    storagePath: keys/Rundeck_Access-Gitlab_Personal_Access_Token-READ_API

    valueExposed: true

  - description: 'The URL to clone the repo via HTTPS, ie https://gitlab.fqdnredacted.com /it/all_win_servers.git'

    hidden: true

    name: HTTPS_Clone_URL

    value: https://gitlab.fqdnredacted.com/support-and-operations/s-and-o-morning-standup-scripts.git

  - description: 'The path to the script to be run, relative to the root of the cloned

      repo'

    hidden: true

    name: Script

    value: Update_Jira_Tickets.ps1

  - hidden: true

    name: JiraAdminPassword

    required: true

    secure: true

    storagePath: keys/JIRA/jiraadmin.pw

    valueExposed: true

  - hidden: true

    name: SPDBPassword

    secure: true

    storagePath: keys/spdb.pw

    valueExposed: true

  - hidden: true

    name: sshuser

    value: Rundeck_Jobs

  plugins:

    ExecutionLifecycle: null

  scheduleEnabled: true

  sequence:

    commands:

    - description: Create data.Remote_Location variable

      exec: write-host "RUNDECK:DATA:Remote_Location=c:\tmp\rundeck\${job.project}\${job.name}\${job.execid}"

      plugins:

        LogFilter:

        - config:

            invalidKeyPattern: \s|\$|\{|\}|\\

            logData: 'false'

            regex: ^RUNDECK:DATA:\s*([^\s]+?)\s*=\s*(.+)$

          type: key-value-data

    - description: Create remote directory structure

      exec: If(!(test-path """${data.Remote_Location}""")) {New-Item -ItemType Directory

        -Force -Path """${data.Remote_Location}"""}

    - description: Clone Repo with Git

      exec: 'git clone $("""${option.HTTPS_Clone_URL}""").replace("https://", """https://NoUserNameNeeded:${option.Rundeck_Access-Gitlab_Personal_Access_Token-READ_API}@""")

        ${data.Remote_Location}'

      plugins:

        LogFilter:

        - config:

            replacement: '[PW_REDACTED]'

          type: mask-passwords

    - description: Execute the Script

      exec: '"""PowerShell.exe -ExecutionPolicy Bypass -File ''${data.Remote_Location}\${option.Script}

        -JiraPassword REDACTED -SharePointPassword REDACTED''"""; "PowerShell.exe

        -ExecutionPolicy Bypass -File ''${data.Remote_Location}\${option.Script}''

        -JiraPassword ${option.JiraAdminPassword} -SharePointPassword  ${option.SPDBPassword}"'

    - description: Cleanup!

      exec: Write-Host """Removing - ${data.Remote_Location}"""; Remove-Item -LiteralPath

        """${data.Remote_Location}""" -Force -Recurse

    keepgoing: false

    strategy: node-first

  timeZone: America/Chicago

  uuid: 08e566e7-5a0c-4797-9e23-b8a86a047be0

 

 

----------

Taylor Hammerling

WEI/GLBRC IS Support & Operations Manager

           thamm...@wisc.edu

           +1-608-890-1780

           preferred pronouns: he/him/his

            https://open.spotify.com/user/snarfsmojo/playlists

 

--
You received this message because you are subscribed to the Google Groups "rundeck-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rundeck-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rundeck-discuss/9a273aa0-3800-477b-b105-2791369d8e8cn%40googlegroups.com.

TAYLOR J HAMMERLING

unread,
Jan 18, 2023, 9:11:31 AM1/18/23
to rundeck...@googlegroups.com

I should probably note that the job definition I sent you is based on a template we use for all of our windows based jobs.  This job is the only one that is causing me grief

 

From: rundeck...@googlegroups.com <rundeck...@googlegroups.com> on behalf of rac...@rundeck.com <rac...@rundeck.com>
Date: Tuesday, January 17, 2023 at 4:53 PM
To: rundeck-discuss <rundeck...@googlegroups.com>
Subject: [rundeck] Re: Issue with Invoke-RestMethod (powershell)ran thru rundeck

--

TAYLOR J HAMMERLING

unread,
Jan 19, 2023, 8:57:05 AM1/19/23
to rundeck...@googlegroups.com

I resolved my issue!  It wasn’t a rundeck issue at all.

 

The node I was executing the script on had powershell 5.1 on it, but I wrote the script using powershell 7.x. Once I installed powershell 7.3 on the node and changed the executable from powershell.exe to pwsh.exe in the job, everything worked.

 

Taylor

Message has been deleted

rac...@rundeck.com

unread,
Jan 19, 2023, 9:05:48 AM1/19/23
to rundeck-discuss
Glad to know! Cheers!
Reply all
Reply to author
Forward
0 new messages