0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Github ActionsでアップロードしたartifactsのDLリンクをslackに通知する

Last updated at Posted at 2024-07-13

はじめに

2023年12月にGitHub ActionsでArtifacts v4が一般利用可能となりました。v4の変更によって、artifactsアップロード後にartifact-idが付与されるようになりました。
https://github.blog/changelog/2023-12-14-github-actions-artifacts-v4-is-now-generally-available/

付与されたartifact-idを使うことでアップロードしたartifactのDLリンクが作れるようになります。

サマリ

次のように書くことでダウンロードリンクが作れます

${{github.server_url}}/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.**actions/upload-artifact@v4で指定したid名**.outputs.artifact-id }}

サンプル

プロジェクトルートフォルダにあるhoge.txtをアップロードしてslackにDLリンクを通知する例を示します。

yaml

jobs: 
  upload-artifacts: 
    *中略*
    steps: 
      - name: Upload artifacts 
        uses: actions/upload-artifact@v4
        id: artifact-upload-step
        with:
          path: hoge.txt

      - name: Send to slack
        if: success()
        uses: slackapi/slack-github-action@v1.26.0
        with:
          payload: |
            {
              "text": "Github Actions実行結果: ${{ job.status }}\nダウンロードリンク: ${{github.server_url}}/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }}",
              "blocks": [
                {
                  "type": "section",
                  "text": {
                    "type": "mrkdwn",
                    "text": "Github Actions実行結果: ${{ job.status }}\nダウンロードリンク: ${{github.server_url}}/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }}"
                  }
                }
              ]
            }
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} 
          SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

実行結果

image.png
image.png

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?