GitHub Actions copy the artifact to 2 runners/vm using single workflow

Viewed 13

I'm using GitHub actions to copy the artifact to the runner/VM, here I added my VM as a self-hosted runner and running the workflow directly on the runner. I'm downloading the artifact from artifactory and copying it to the deployment location, Now, I Need to do the same thing on another runner/VM as I have an identical deployment VM for the application. To achieve this, I have copied the same job and changed the 'runs-on' value with a different runner name which is my second VM. below is my workflow code.

My question is, Instead of 2 jobs, how can we run in a single job for all VMs related to dev? let's say, Assume that I have 4 VMs for the Dev environment and 3 VMs for QA, and 5 VMs for Prod

can someone help with this or do we need to continue with the same approach whatever I'm doing right now?

name: Deployment_workflow

on:
  workflow_dispatch:
    inputs:
      dev:
        type: boolean
        required: false
        default: false
      qa:
        type: boolean
        required: false
        default: false
jobs:
    dev_deploy_1:
      if: github.event.inputs.dev =='true'
      runs-on: dev-vm-1
      steps:
        - name: Download the artifact from artifactory
          run: |
            cd /tmp
            curl -u ${ARTIFACTORY_USER}:${ARTIFACTORY_ENCRYPT} -T dep-deploy-1.war "$(ARTIFACTORY_URL)/artifactory/general-artifacts/dep-deploy-1.war"
        - name: copy the file from /tmp to deployment location
          run: |
            cp /tmp/dep-deploy-1.war /var/lib/app_deploy_dir

    dev_deploy_2:
      if: github.event.inputs.dev =='true'
      runs-on: dev-vm-2
      steps:
        - name: Download the artifact from artifactory
          run: |
            cd /tmp
            curl -u ${ARTIFACTORY_USER}:${ARTIFACTORY_ENCRYPT} -T dep-deploy-2.war "$(ARTIFACTORY_URL)/artifactory/general-artifacts/dep-deploy-2.war"
        - name: copy the file from /tmp to deployment location
          run: |
            cp /tmp/dep-deploy-1.bar /var/lib/app_deploy_dir
0 Answers
Related