1
votes

I have a main job like the below and two other parallel jobs are dependent on the first job including secret generation and node module installation like secret setup and install node module.

enter image description here

I tried to make it work with needs but all the environment setup is gone with needs. And reusable workflow seems to just setup keys.

name: build
on: [push]
jobs:
   codepull:
      runs-on: ubuntu-latest
      steps:

         - uses: actions/setup-node@v3
           with:
           node-version: '16.16.0'
         
         - name: install node module
           run |
             yarn

          - name: secrets
           run |
             yarn secrets

       codepull-ios:
           - name: build ios
             run |
                ...

    codepull-ios:
       runs-on: ubuntu-latest
       steps:
           ...

    codepull-android:
       runs-on: ubuntu-latest
       steps:
           ...

I checked reusable workflow but those seems only for setting up env variables.

Anyone tried to do similar things?

1
Please share what you get and what you expected. It is not clear to me what you're asking. - rethab
Perhaps also create a minimal reproducer - rethab

1 Answers

0
votes

jobs runs in it's own environment so do not share nothing by default. By you can define jobs output and use it in the dependant job, like:

name: build
on: [push]
jobs:
   codepull:
      runs-on: ubuntu-latest
      outputs: # define here the job output
        one-secret: ${{ steps.secret.outputs.my-secret }}
      steps:

         - uses: actions/setup-node@v3
           with:
           node-version: '16.16.0'
         
         - name: install node module
           run |
             yarn

          - name: secrets
            id: secret
           run |
             yarn secrets

             secretkey=$(cat password.txt) # stupid example to take some var from somewhere
             echo "::set-output name=my-secret::$secretkey"


       codepull-ios:
           - name: build ios
             run |
                ...

    codepull-ios:
       runs-on: ubuntu-latest
       needs: 
         - codepull
       steps:
         -run:
           echo needs.codepull.outputs.one-secret # use the secrets
           ...

    codepull-android:
       runs-on: ubuntu-latest
       steps:
           ...

Some link to the doc about jobs output