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

How do I get the logs for a service?

Solved! Go to Solution.

Hi,

 

I've got several services that my job depends on. I'm fairly certain one of them is misbehaving. I'd like to view the logs for them, but, I can't see them anywhere within github actions. Any suggestions?

 

 

Cheers!

5 Replies
Highlighted
Pilot Lvl 1
Message 2 of 6

Re: How do I get the logs for a service?

At the top right corner of the Actions tab, there is a link to view the raw logs. 

 

image.png

Solution
GitHub Staff
Message 3 of 6

Re: How do I get the logs for a service?

https://help.github.com/en/articles/contexts-and-expression-syntax-for-github-actions#job-context

 

You can get the ID of a service container with "${{ job.services.<service_id>.id }}"

 

With that you can do any regular docker operation you'd like, for example:

 

docker logs "${{ job.services.<service_id>.id }}"

 

Heres a full working sample I have of using mysql:

 

jobs:
  test:
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mysql:5.7
        env:
          MYSQL_ROOT_PASSWORD: password
        ports:
          - 3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
    steps:
    - name: Verify MySQL connection from host
      run: |
        echo "${{ toJson(job) }}"
        sudo apt-get install -y mysql-client
        mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -uroot -ppassword -e "SHOW DATABASES"
        docker logs "${{ job.services.mysql.id }}"

The logs from the service container will then be in the logs of the step where you ran `docker logs`, as expected 

 

Depending on the service, `docker logs` may not work. See: https://docs.docker.com/v17.09/engine/admin/logging/view_container_logs/

 

 

Highlighted
Copilot Lvl 2
Message 4 of 6

Re: How do I get the logs for a service?

Thank you!

 

Not sure where to put feature requests... would be good to have these automatically extracted and viewable within a tab somewhere in the UI. When a build fails I'd rather not have to start adding calls to docker to try and diagnose the failure :)

Highlighted
Pilot Lvl 1
Message 5 of 6

Re: How do I get the logs for a service?

This would not work if the "Initialize containers" step has failed. How do we troubleshoot such a failure?

See for example https://github.com/api-platform/core/runs/260470103#step:2:133

Highlighted
Mission Specialist Lvl 1
Message 6 of 6

Re: How do I get the logs for a service?

I'd like to know this too, I am having a similar issue with a MariaDB service (which incidentally was working fine a couple of days ago).