Chris Munoz
02/17/2022, 5:38 PMcan-i-deploy
.
Locally, when I run the script, everything works and I get a response from pactflow. But when the requests runs on Octopus, it comes back with a 404. I am printing out the url that is being hit, and it works fine on Postman.
Has anyone ran into this issue? Or is there logs on Pactflow that I can look at?Tawfik Nouri
02/17/2022, 7:30 PMChris Munoz
02/17/2022, 7:35 PMparam(
[string]$pactBroker = "<https://ess.pactflow.io>",
[Parameter(Mandatory = $true)]
[string]$pacticipant,
[Parameter(Mandatory = $true)]
[string]$toEnv,
[Parameter(Mandatory = $true)]
[string]$pactBrokerToken,
[string]$dataDogEventsUrl = "<https://api.datadoghq.com/api/v1/events>",
[Parameter(Mandatory = $true)]
[string]$dataDogToken
)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$PSVersionTable
$firstLine = Get-Content "..\..\ReleaseNotes.md" -First 1
$branchName = $firstLine -Replace "Branch: ", ""
$canIDeployUrl = "$pactBroker/pacticipants/:pacticipant/latest-version/:tag/can-i-deploy/to/:toEnv"
$pactFlowHeaders = @{ "Content-Type" = "application/json"; "Accept" = "application/hal+json"; 'Authorization' = 'Bearer ' + $pactBrokerToken; }
$encodedPacticipant = [Uri]::EscapeDataString($pacticipant)
$encodedTag = [Uri]::EscapeDataString($branchName)
$encodedToEnv = [Uri]::EscapeDataString($toEnv)
$formattedCanIDeployUrl = (($canIDeployUrl -Replace ":pacticipant", $encodedPacticipant) -Replace ":tag", $encodedTag) -Replace ":toEnv", $encodedToEnv
Write-Host "`nChecking if '$pacticipant' with tag '$branchName' can be deployed to '$toEnv':"
Write-Host "`t$formattedCanIDeployUrl`n"
$pactFlowResponse = Invoke-RestMethod $formattedCanIDeployUrl -Method "GET" -Headers $pactFlowHeaders
Write-Host (ConvertTo-Json $pactFlowResponse -Depth 10)
if (($null -eq $pactFlowResponse.summary.deployable) -or ($true -eq $pactFlowResponse.summary.deployable)) {
exit 0
}
else {
$dataDogEvent = @{}
$dataDogEvent.alert_type = "error"
$dataDogEvent.title = "$pacticipant Failed to Deploy to $toEnv"
$dataDogEvent.text = $pactFlowResponse.summary.reason
$dataDogEvent.tags = [System.Collections.ArrayList]@()
$dataDogEvent.tags.Add("documents_service")
$dataDogEvent.tags.Add("environment:$toEnv")
$dataDogHeaders = @{ "Content-Type" = "application/json"; "Accept" = "application/json"; 'DD-API-KEY' = $dataDogToken; }
Invoke-RestMethod $dataDogEventsUrl -Method "POST" -Headers $dataDogHeaders -Body (ConvertTo-Json $dataDogEvent)
exit 1
}
Chris Munoz
02/17/2022, 7:36 PMChris Munoz
02/17/2022, 7:47 PMName Value
---- -----
PSVersion 5.1.14409.1018
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1018
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Checking if 'Documents Service' with tag 'task/SRVC-233-pactflow-deploying' can be deployed to 'devsb':
<https://ess.pactflow.io/pacticipants/Documents%20Service/latest-version/task%2FSRVC-233-pactflow-deploying/can-i-deploy/to/devsb>
InvalidOperation: The remote server returned an error: (404) Not Found.
At C:\Octopus\Work\20220215231229-1676071-4608\Infrastructure\Scripts\CanIDeploy-Octopus.ps1:33 char:21
+ ... wResponse = Invoke-RestMethod $formattedCanIDeployUrl -Method "GET" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at <ScriptBlock>, C:\Octopus\Work\20220215231229-1676071-4608\Infrastructure\Scripts\CanIDeploy-Octopus.ps1: line 33
at <ScriptBlock>, <No file>: line 1
at <ScriptBlock>, C:\Octopus\Work\20220215231229-1676071-4608\Infrastructure\Scripts\Octopus.FunctionAppenderContext.ps1: line 185
at <ScriptBlock>, C:\Octopus\Work\20220215231229-1676071-4608\Infrastructure\Scripts\Bootstrap.Octopus.FunctionAppenderContext.ps1: line 3705
at <ScriptBlock>, <No file>: line 1
at <ScriptBlock>, <No file>: line 1
The remote script failed with exit code 1
The action Can I Deploy on OctopusServer failed
Tawfik Nouri
02/17/2022, 8:42 PMTawfik Nouri
02/17/2022, 8:43 PMChris Munoz
02/17/2022, 8:47 PMChris Munoz
02/17/2022, 8:47 PMMatt (pactflow.io / pact-js / pact-go)