Hello everyone, I am running into an issue that I ...
# pactflow
c
Hello everyone, I am running into an issue that I hope someone can help me with. My company uses Octopus Deploy but they don't have docker installed in the worker agents, so I've had to create a powershell script instead of
can-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?
t
Hi Chris Can you share your script?
c
Copy code
param(
  [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
}
@Tawfik Nouri ^
These are the logs from Octopus:
Copy code
Name							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
t
Sorry I used another solution. My script download the pact-cli from GitHub and use it as cli like docker ....
I can share with you my scripts (DM).
c
Sure, that would be great
Thanks
👍 1
m
Thanks Tawfik - yes, we recommend you just use our CLI tools directly in this case. You don’t have to use docker
👍 1