1

I have a Github actions workflow that consists of two dependent jobs:

  1. Job A does change detection: Which modules in my monorepo changed.
  2. Job B is a matrix job, iterating of all changed modules (the working directories are the result of job a) and doing some CI stuff.

Now I want to use AWS CodeBuild to run as a self hosted runner for GitHub actions (so I can run everything in my VPC).

While this basically works, for each job, the code gets checked out to a different folder.

Job A return this folder for the target path to a changed module /codebuild/output/src1067370363/src/actions-runner/_work/myorg/myrepo/packages/module-a

But in Job B the source code ist checked out to /codebuild/output/src1107479956/src/actions-runner/_work/myorg/myrepo

Therefore all CI commands fail since the directory does not exist.

Is it possible in CodeBuild to change the directory?

2 Answers 2

2

The source path changes every build, but you can use the CODEBUILD_SRC_DIR environment variable to get the relative path. In self hosted runner builds, the value looks like /codebuild/output/src3071359377/src. You can check more detailed information on CodeBuild environment variables here.

Sign up to request clarification or add additional context in comments.

Comments

0

Let’s say that jobA created a matrix of of relative directories to be built and the variable name in the matrix is dir. JobA published the matrix JSON as an output called ‘changed’.

The JSON would look like this

{“dir”: [“packages/a”, “packages/b”, “packages/c”]}

You can set working-directory for the CI steps of jobB from the matrix.

jobs:
  jobB:
    Needs: jobA
    runs-on: ubuntu-latest
    strategy:
      matrix: ${{ fromJSON(needs.jobA.outputs.changed) }}
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: CI
        run: |
          Echo CI
        working-directory: ${{ matrix.dir }}

2 Comments

Thanks, but this does not solve the issue. I have the exact same setup, but the repo in job a is checked out to a different folder than the repo in job b. So the paths don't match between the change detection job and the second (actual) job
I see what you mean - each job from a matrix has its own unique repo directory. JobA needs to return a relative path. Updated answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.