DeployHubProject / DeployHub-Pro

DeployHub Pro Pipeline Status Project
https://www.openmakesoftware.com/application-release-automation-for-continuous-delivery/
Other
11 stars 4 forks source link

powershell script as function not working #252

Closed piyush94 closed 5 years ago

piyush94 commented 5 years ago

Scenario: function

action

dmscript

Error: PLAY [Execute File] ****

TASK [Execute File] **** fatal: [ustr-uvm-12271.na.uis.unisys.com]: FAILED! => {"changed": false, "cmd": "C:\temp\examplescript.ps1 code", "msg": "Exception calling \"RunCommand\" with \"5\" argument(s): \"Failed to create new process (%1 is not a valid Win32 application, Win32ErrorCode 193)\"", "rc": 2} to retry, use: --limit @/tmp/tmpz2vc6t3n/runit.retry

PLAY RECAP ***** ustr-uvm-12271.na.uis.unisys.com : ok=0 changed=0 unreachable=0 failed=1

piyush94 commented 5 years ago

CC: @svisagan83

sbtaylor15 commented 5 years ago

What output does the powershell program return, json? CC: @svisagan83

piyush94 commented 5 years ago

The script is not returning anything. We assumed that in the result variable, the exit code of the script will be captured. Does it work this way or we have to explicitly return a value? Again main issue is that script is not getting executed if arguments are passed, even if nothing is returned. Also if we use named parameters like script.ps1 -appName "code", it throws below error:

Usage: dmtransfer [OPTIONS] [EXEC]... 

Try "dmtransfer --help" for help. 

Error: no such option: -a
sbtaylor15 commented 5 years ago

Let me check on the passing back of the return code to the DM Script. I know that json output from the script is automatically parsed into DM Script variables.

sbtaylor15 commented 5 years ago

The non-zero return code from the powershell script causes an exception to be thrown in the DMScript. This exception needs to be caught and transformed into a return code.

I am working on an example of how this should be structured.

CC: @svisagan83

piyush94 commented 5 years ago

script:

param (
    [Parameter(Mandatory=$true)]
    [string]$AppName
)

$app = Get-WmiObject -Class Win32_Product | Where-Object { 
    $_.Name -like $AppName
}

if($null -eq $app) {
    Write-Output "false"
    # exit 0
} else {
    Write-Output "true"
    # exit -1
}

CC: @svisagan83

sbtaylor15 commented 5 years ago

@piyush94 - The latest image has the fix. Here are screen shots for configuring the Action.

param (
    [Parameter(Mandatory=$true)]
    [string]$AppName
)

$app = Get-WmiObject -Class Win32_Product | Where-Object {
    $_.Name -like $AppName
}

if($null -eq $app) {
        Write-Output "0"
    # exit 0
} else {
        Write-Output "1"
    # exit -1
}

image image image image image image image

CC: @svisagan83

docker pull quay.io/deployhub/deployhub-pro@sha256:7b4c3289a8b692b4e9817dfad4846b51233a266399c7e63acd20e6799a99035d

piyush94 commented 5 years ago

@sbtaylor15 No luck, still not working.

param (
    [Parameter(Mandatory=$true)]
    [string]$AppName
)

$app = Get-WmiObject -Class Win32_Product | Where-Object { 
    $_.Name -like $AppName
}

if($null -eq $app) {
    Write-Output "false"
    # exit 0
} else {
    Write-Output "true"
    # exit -1
}

image image image image

PLAY [Execute File] ************************************************************

TASK [Execute File] ************************************************************
fatal: [USTR-UVM-12271.na.uis.unisys.com]: FAILED! => {"changed": false, "cmd": "C:\\temp\\examplescript.ps1 -appName code", "msg": "Exception calling \"RunCommand\" with \"5\" argument(s): \"Failed to create new process (%1 is not a valid Win32 application, Win32ErrorCode 193)\"", "rc": 2}
 to retry, use: --limit @/tmp/tmp8mhz91fc/runit.retry

PLAY RECAP *********************************************************************
USTR-UVM-12271.na.uis.unisys.com : ok=0    changed=0    unreachable=0    failed=1 

image

image

CC: @svisagan83

piyush94 commented 5 years ago

@sbtaylor15 Found a workaround: image This is working.

CC: @svisagan83

sbtaylor15 commented 5 years ago

@piyush94 - Added code to default the necessary command shell if one is not supplied.

.ps1 = powershell.exe -File .vbs = cscript.exe /nologo .js = cscript.exe /nologo .wsf = cscript.exe /nologo

CC: @svisagan83

sbtaylor15 commented 5 years ago

@piyush94 - please remove your work around and let us know if the default is used.

piyush94 commented 5 years ago

@sbtaylor15 Not working without workaround

PLAY [Execute File] ************************************************************

TASK [Execute File] ************************************************************
fatal: [USTR-UVM-12271.na.uis.unisys.com]: FAILED! => {"changed": false, "cmd": "C:\\temp\\examplescript.ps1 -appName Zoom", "msg": "Exception calling \"RunCommand\" with \"5\" argument(s): \"Failed to create new process (%1 is not a valid Win32 application, Win32ErrorCode 193)\"", "rc": 2}
 to retry, use: --limit @/tmp/tmpyik2mmzf/runit.retry

PLAY RECAP *********************************************************************
USTR-UVM-12271.na.uis.unisys.com : ok=0    changed=0    unreachable=0    failed=1 

CC: @svisagan83

sbtaylor15 commented 5 years ago

@piyush94 - Added default shell for scripts that exists already on remote end point. CC: @svisagan83

pull latest

piyush94 commented 5 years ago

@sbtaylor15 It'sworking now.

CC: @svisagan83