首頁  >  文章  >  開發工具  >  如何在 github actions 中執行 shell 腳本

如何在 github actions 中執行 shell 腳本

Susan Sarandon
Susan Sarandon原創
2024-10-10 12:44:20808瀏覽

本文提供了在 GitHub Actions 工作流程中執行 shell 腳本的指南。它涵蓋了基於shell 腳本更改觸發工作流程、將變數從腳本傳遞到作業以及在單一工作中執行多個shell 腳本

如何在 github actions 中執行 shell 腳本

我如何在GitHub Actions 工作流程中執行shell 腳本?

要在 GitHub Actions 工作流程中執行 shell 腳本,您可以使用 run 指令。 run 指令採用 shell 腳本作為輸入並在執行器上執行它。

例如,以下 GitHub Actions 工作流程執行 hello.sh shell 腳本:

<code>name: Execute a shell script

on: [push, pull_request]

jobs:
  execute-shell-script:
    runs-on: ubuntu-latest
    steps:
      - name: Execute shell script
        run: ./hello.sh</code>

我可以根據 shell 腳本的變更觸發 GitHub Action 嗎?

是的,您可以根據 shell 腳本的變更觸發 GitHub Action。為此,您可以在 GitHub Actions 工作流程文件中使用 on 關鍵字。 on 關鍵字指定將觸發工作流程的事件。

例如,以下GitHub Actions 工作流程將在execute-shell-script shell 腳本發生變更時觸發hello.sh 作業:

<code>name: Trigger GitHub Action on shell script changes

on:
  push:
    paths:
      - hello.sh

jobs:
  execute-shell-script:
    runs-on: ubuntu-latest
    steps:
      - name: Execute shell script
        run: ./hello.sh</code>

如何將變數從shell 腳本傳遞到GitHub Action 作業?

您可以使用

GitHub Actions 工作流程文件中的關鍵字。 env 關鍵字指定作業可用的環境變數。 env

例如,以下 GitHub Actions 工作流程將

變數從 FOO shell 腳本傳遞到 hello.sh 作業:execute-shell-script

以上是如何在 github actions 中執行 shell 腳本的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn