How to do sequentially deployment when we fetch environment dynamically using strategy and matrix. needs doesn't works dynamically. #141060
Replies: 1 comment
-
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
-
Select Topic Area
Question
Body
I am retrieving environments dynamically using strategy and matrix. I want to do sequence deployment not parallel. I am trying to add needs but needs doesn't work dynamically. Please help to do sequence deployment. For example, if prod deployment is happening it should wait for lower environment. Once lower environment deploys then only Prod deploy
name: Env Read
on:
workflow_dispatch:
jobs:
get-environments:
runs-on: ubuntu-latest
outputs:
names: ${{ steps.set_env.outputs.names }}
steps:
- name: Get Environments
uses: octokit/[email protected]
id: get_env
with:
route: GET /repos/${{ github.repository }}/environments?per_page=100 # If we ever have >100 deployments, we'll need to paginate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set output
id: set_env
# run: echo "names=$(echo $NAMES | jq -c '[.[] | select(startswith("[${{ github.ref_name }}]"))]' -j)" >> $GITHUB_OUTPUT
env:
NAMES: ${{ toJson(fromJson(steps.get_env.outputs.data).environments.*.name) }}
run: |
# use heredoc with random delimiter for multiline JSON
delimiter="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 20)"
echo "names<<$delimiter
$NAMES
$delimiter" >> "$GITHUB_OUTPUT"
deploy:
needs:
- get-environments
runs-on: ubuntu-22.04
strategy:
matrix:
environment: ${{ fromJson(needs.get-environments.outputs.names) }}
environment:
name: ${{ matrix.environment }}
steps:
- name: Echo
run: echo ${{ matrix.environment }}
Beta Was this translation helpful? Give feedback.
All reactions