Jobs in the same workflow do not see file system?

I have a workflow that builds and runs tests.

The project is a .NET project with multi-targeting (.NET Framework and .NET Standard TFMs).

I’ve decided to split the workflows into two jobs, one for building and one for testing, but it looks like the jobs are all isolated and the test job does not have access to the build job’s results.

name: Build and Test

on: [push]

jobs:
  Build:
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@v1
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
    - name: Build
      run: dotnet build src --configuration Release
  Test:
    needs: [Build]
    runs-on: windows-latest
    strategy:
      matrix:
        tfm: ['netcoreapp2.1', 'net461']
    steps:
    - name: Run tests (target framework ${{ matrix.tfm }})
      run: dotnet test src --configuration Release --framework ${{ matrix.tfm }} --list-tests

I’d like to be able to run tests w/o rebuild and restoring (--no-builld --no-restore). Is this possible?

Thank you.

Each Job has its own runs-on machine. Jobs runs on different machines. So yes, jobs are isolated.

If you want to share build job’s results to test job, you can use upload artifacts (actions/upload-artifact@v1.0.0) and download artifacts actions (actions/download-artifact@v1.0.0).

In my example, after dotnet build action , I add an upload artifact action with name ForTest and appropriate path.

Then in Test job, before dotnet test action, I add a Download artifact action with the same name ForTest. Then in dotnet test action, add working-directory.  You need to make sure the directory contain a project or solution file.

name: .NET Core

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 2.2.108
    - name: Build with dotnet
      run: dotnet build --configuration Release CoreWebApplication1/CoreWebApplication1.sln
    - name: Upload artifact
      uses: actions/upload-artifact@v1.0.0
      with:
        name: ForTest
        path: CoreWebApplication1

  test:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Download artifact
        uses: actions/download-artifact@v1.0.0
        with:
          name: ForTest

      - name: test with dotnet
        run: dotnet test
        working-directory: ./ForTest
1 Like

You can indeed share artifacts between jobs.  But in this case it would probably be easier and faster to make build and test two different steps of same job.

name: .NET Core

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 2.2.108
    - name: Build
      run: dotnet build --configuration Release CoreWebApplication1/CoreWebApplication1.sln
      - name: Test
        run: dotnet test
        working-directory: ./ForTest