I have a workflow with 2 jobs in the strategy matrix like the one below.
Both jobs have protection rules for Environment
prompting for Manual approval.
Upon Approving and executing the first job, I wish to pass the job-name
of the other & get the triggered automatically.
name: NEW Loop Over Comma-Separated Values
on:
push:
branches:
- main
jobs:
createloopmatrix:
runs-on: windows-latest
outputs:
MATRIX: ${{ steps.set-matrix.outputs.MATRIX }}
ENV-VARS: ${{ steps.set-matrix.outputs.ENV-VARS }}
steps:
- name: Run PowerShell
id: set-matrix
shell: pwsh
run: |
$EnvNamesJSONVariable = @{}
$envList = New-Object System.Collections.ArrayList
$displayList = New-Object System.Collections.ArrayList
$color = "hello, yellow"
$values = $color.Split(',')
$matrix = @()
$envVars = @{}
foreach ($value in $values) {
$matrixName = "MA_$value"
$matrix += @{ "DISPLAYLIST" = $matrixName; "CUSTOMENVNAME" = $value }
$envVars."$value" = $value
Write-Output "Value: $value"
}
echo "MATRIX=$($matrix | ConvertTo-Json -Compress -Depth 100)" >> "$env:GITHUB_OUTPUT"
echo "ENV-VARS=$($envVars | ConvertTo-Json -Compress -Depth 100)" >> "$env:GITHUB_OUTPUT"
Trigger_Service:
name: ${{ matrix.DISPLAYLIST }}
needs: [createloopmatrix]
runs-on: windows-latest
strategy:
matrix:
include: ${{ fromJson(needs.createloopmatrix.outputs.MATRIX) }}
environment:
name: ${{ matrix.CUSTOMENVNAME }}
steps:
- name: Split Matrix name for use
run: |
Write-Host "Inside Matrix"
Snapshot of the run:
As you can see if I manually approve MA_hello
the solution I’m expecting here should run and trigger MA_yellow
job without the need for manual approval.
Kindly suggest.