Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 4

Get timing info of the previous job

I have a workflow that contains two jobs. First is deploying my project to test server and second is sending notifications if the deploy succeeded.

 

 

name: Deploy Release

on:
  release:
    types: [published]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:

    - name: Checkout
      uses: actions/checkout@v1

    - name: Install Dependencies
      run: |
        npm install
    - name: Test
      run: |
        npm run test:ci
      
    - name: Build
      run: |
        npm run build
        
    - name: Deploy (FTP to Azure)
      uses: SamKirkland/FTP-Deploy-Action@2.0.0
      env:
        FTP_SERVER: ${{ secrets.FTP_SERVER_AZURE_TEST }}
        FTP_USERNAME: ${{ secrets.FTP_USERNAME_AZURE_TEST }}
        FTP_PASSWORD: ${{ secrets.FTP_PASSWORD_AZURE_TEST }}
        REMOTE_DIR: site/wwwroot
        LOCAL_DIR: build
        METHOD: ftp
        ARGS: --no-empty-dirs --delete
        
  send-notification:
    needs: deploy
    runs-on: ubuntu-latest
    steps:

    - name: Echo
      run: echo $EVENT
      env:
        EVENT: ${{ tojson(github.event) }}

    - name: Slack
      uses: rtCamp/action-slack-notify@v1.0.0
      env:
        SLACK_CHANNEL: yolocar-pl
        SLACK_TITLE: 'Release ${{ github.event.release.tag_name }} - ${{ github.event.release.name }} :beer:'
        SLACK_MESSAGE: >
          Release info:
          
          ${{ github.event.release.body }}
        SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}

The second job depends on the first.

My idea is to send extra info in the notification. I'd like to add info with how long the deploy took, for example, 5 minutes.

In action details (in Actions tab on GitHub website) I see how long each job took, but how can I get timing info from second job?

 

3 Replies
Highlighted
GitHub Staff
Message 2 of 4

Re: Get timing info of the previous job

You should be able to query the jobs for the current run using the API https://developer.github.com/v3/actions/workflow_jobs/.   You can get the run_id from teh github context https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-express....

Highlighted
Copilot Lvl 3
Message 3 of 4

Re: Get timing info of the previous job

Thank you for your reply.

I'll try to build something, an example of how to call that inside action would be awesome :)

 

Just a reminder, I have two jobs in my workflow, first one is deploying my app and second is sending a summary.

So in my second job I'd like to get info how long the first job took.

 

So I should do a request to GET /repos/:owner/:repo/actions/runs/:run_id/jobs (where run_id is from context github.run_id),

then I should find a job with a specific name, get it id and then do a request GET /repos/:owner/:repo/actions/jobs/:job_id to get that job details.

 

Highlighted
GitHub Staff
Message 4 of 4

Re: Get timing info of the previous job

Yes that should give you all of the information.  

 

You can use curl and jq inside a run step to call the API which should be very similar to the examples in the documentation.