{"meta":{"title":"Azure Pipelines から GitHub Actions への移行","intro":"GitHub Actions とAzure Pipelinesは、いくつかの構成を共通に持っているため、GitHub Actions への移行は比較的容易であることを意味します。","product":"GitHub Actions","breadcrumbs":[{"href":"/ja/actions","title":"GitHub Actions"},{"href":"/ja/actions/tutorials","title":"チュートリアル"},{"href":"/ja/actions/tutorials/migrate-to-github-actions","title":"GitHub Actions に移行する"},{"href":"/ja/actions/tutorials/migrate-to-github-actions/manual-migrations","title":"手動移行"},{"href":"/ja/actions/tutorials/migrate-to-github-actions/manual-migrations/migrate-from-azure-pipelines","title":"Azure Pipelinesから移行する"}],"documentType":"article"},"body":"# Azure Pipelines から GitHub Actions への移行\n\nGitHub Actions とAzure Pipelinesは、いくつかの構成を共通に持っているため、GitHub Actions への移行は比較的容易であることを意味します。\n\n## 概要\n\nAzure PipelinesとGitHub Actionsでは、コードを自動的にビルド、テスト、公開、リリース、およびデプロイするワークフローを作成できます。 Azure PipelinesとGitHub Actionsは、ワークフローの設定において似ているところがあります。\n\n* ワークフローの設定ファイルはYAMLで書かれ、コードのリポジトリに保存されます。\n* ワークフローには 1 つ以上のジョブが含まれます。\n* ジョブには 1 つ以上のステップもしくは個別のコマンドが含まれます。\n* ステップもしくはタスクは、再利用とコミュニティとの共有が可能です。\n\n詳しくは、「[GitHub Actionsについて](/ja/actions/learn-github-actions/understanding-github-actions)」をご覧ください。\n\n## 主要な相違点\n\nAzure Pipelinesから移行する場合は、次の違いを考慮してください。\n\n* Azure Pipelinesでは、従来の *classic エディター* がサポートされています。これにより、YAML ファイルでパイプライン定義を作成する代わりに、GUI エディターで CI 構成を定義できます。 GitHub Actionsはワークフローの定義にYAMLファイルを使い、グラフィカルなエディタはサポートしていません。\n* Azure Pipelinesを使用すると、ジョブ定義の一部の構造を省略できます。 たとえば、ジョブが 1 つだけしかないなら、ジョブを定義する必要はなく、ステップだけを定義すれば済みます。 GitHub Actionsは明示的な設定が必要であり、YAMLの構造は省略できません。\n* Azure Pipelinesでは、YAML ファイルで定義\\_stages\\_をサポートしています。これは、デプロイ ワークフローの作成に使用できます。 GitHub Actionsでは、ステージは個別のYAMLワークフローファイルに分割しなければなりません。\n* オンプレミスAzure Pipelinesビルド エージェントは、機能を使用して選択できます。 GitHub Actionsのセルフホステッド ランナーは、ラベルで選択できます。\n\n## ジョブとステップの移行\n\nAzure Pipelinesのジョブとステップは、GitHub Actions のジョブとステップとよく似ています。 どちらのシステムでも、ジョブは以下の特徴を持ちます。\n\n* ジョブは、順番に実行される一連のステップを持ちます。\n* ジョブは、個別の仮想マシンまたは個別のコンテナで実行されます。\n* ジョブは、既定では並列に実行されますが、順次実行するように設定することもできます。\n\n## スクリプトのステップの移行\n\nスクリプトやシェルのコマンドを、ワークフロー中のステップとして実行できます。 Azure Pipelinesでは、`script` キーを使用するか、`bash`、`powershell`、または `pwsh` キーを使用してスクリプト ステップを指定できます。 スクリプトは [Bash タスク](https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/bash?view=azure-devops)または [PowerShell タスク](https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell?view=azure-devops)への入力として指定することもできます。\n\nGitHub Actions では、`run` キーを使ってすべてのスクリプトを指定します。 特定のシェルを選択するには、スクリプトを提供する際に `shell` キーを指定します。 詳しくは、「[GitHub Actions　のワークフロー構文](/ja/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun)」をご覧ください。\n\n以下は、それぞれのシステムにおける構文の例です。\n\n### スクリプト ステップのAzure Pipelines構文\n\n```yaml\njobs:\n  - job: scripts\n    pool:\n      vmImage: 'windows-latest'\n    steps:\n      - script: echo \"This step runs in the default shell\"\n      - bash: echo \"This step runs in bash\"\n      - pwsh: Write-Host \"This step runs in PowerShell Core\"\n      - task: PowerShell@2\n        inputs:\n          script: Write-Host \"This step runs in PowerShell\"\n```\n\n### スクリプト ステップの GitHub Actions 構文\n\n```yaml\njobs:\n  scripts:\n    runs-on: windows-latest\n    steps:\n      - run: echo \"This step runs in the default shell\"\n      - run: echo \"This step runs in bash\"\n        shell: bash\n      - run: Write-Host \"This step runs in PowerShell Core\"\n        shell: pwsh\n      - run: Write-Host \"This step runs in PowerShell\"\n        shell: powershell\n```\n\n## スクリプトのエラー処理の差異\n\nAzure Pipelinesでは、出力が `stderr` に送信された場合にエラーが発生するようにスクリプトを構成できます。 GitHub Actionsはこの設定をサポートしていません。\n\nGitHub Actionsは、可能な場合にはシェルを\"fail fast\"に設定します。これは、スクリプト中のコマンドの 1 つがエラーコードで終了した場合に即座にスクリプトを停止させるものです。 これに対し、Azure Pipelinesでは、エラーが発生するとすぐに終了するように明示的な構成が必要です。 詳しくは、「[GitHub Actions　のワークフロー構文](/ja/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference)」をご覧ください。\n\n## Windowsの既定のシェルの違い\n\nAzure Pipelinesでは、Windows プラットフォーム上のスクリプトの既定のシェルは、Command シェル (*cmd.exe*) です。 GitHub Actions では、Windows プラットフォーム上のスクリプトの既定のシェルは PowerShell です。 PowerShellは、組み込みコマンド、変数の展開、フロー制御で多少の差異があります。\n\nシンプルなコマンドを実行するなら、コマンドシェルのスクリプトを変更なしにPowerShellで実行できるかもしれません。 しかしほとんどの場合は、PowerShellの構文でスクリプトをアップデートするか、GitHub Actionsに対してスクリプトをPowerShellではなくコマンドシェルで実行するように指定することになります。\n`shell` を `cmd` として指定することでこれを実行できます。\n\n以下は、それぞれのシステムにおける構文の例です。\n\n### 既定で CMD を使用する Azure Pipelines の構文\n\n```yaml\njobs:\n  - job: run_command\n    pool:\n      vmImage: 'windows-latest'\n    steps:\n      - script: echo \"This step runs in CMD on Windows by default\"\n```\n\n### CMD を指定するための GitHub Actions 構文\n\n```yaml\njobs:\n  run_command:\n    runs-on: windows-latest\n    steps:\n      - run: echo \"This step runs in PowerShell on Windows by default\"\n      - run: echo \"This step runs in CMD on Windows explicitly\"\n        shell: cmd\n```\n\n詳しくは、「[GitHub Actions　のワークフロー構文](/ja/actions/using-workflows/workflow-syntax-for-github-actions#using-a-specific-shell)」をご覧ください。\n\n## 条件と式の構文の移行\n\nAzure PipelinesとGitHub Actionsは、どちらもステップを条件付きで実行できます。 Azure Pipelinesでは、条件式は `condition` キーを使用して指定されます。 GitHub Actionsでは、条件式は `if` キーを使って指定します。\n\nAzure Pipelinesは、式内の関数を使用して、ステップを条件付きで実行します。 それに対し、GitHub Actionsはinfix表記を使います。 たとえば、Azure Pipelines の `eq` 関数をGitHub Actions の `==` 演算子に置き換える必要があります。\n\n以下は、それぞれのシステムにおける構文の例です。\n\n### 条件式の Azure Pipelines 構文\n\n```yaml\njobs:\n  - job: conditional\n    pool:\n      vmImage: 'ubuntu-latest'\n    steps:\n      - script: echo \"This step runs with str equals 'ABC' and num equals 123\"\n        condition: and(eq(variables.str, 'ABC'), eq(variables.num, 123))\n```\n\n### 条件式の GitHub Actions 構文\n\n```yaml\njobs:\n  conditional:\n    runs-on: ubuntu-latest\n    steps:\n      - run: echo \"This step runs with str equals 'ABC' and num equals 123\"\n        if: ${{ env.str == 'ABC' && env.num == 123 }}\n```\n\n詳しくは、「[ワークフロー内とアクション内で式を評価する](/ja/actions/learn-github-actions/expressions)」をご覧ください。\n\n## ジョブ間の依存関係\n\nAzure Pipelinesと GitHub Actions の両方で、ジョブの依存関係を設定できます。 どちらのシステムでも、既定ではジョブは並行に実行されますが、ジョブの依存関係を明示的に指定できます。 Azure Pipelinesでは、これは `dependsOn` キーを使用して行われます。 GitHub Actions では、`needs` キーを使って行います。\n\n以下は、それぞれのシステムにおける構文の例です。 ワークフローは `initial` という名前の最初のジョブを開始し、そのジョブが完了すると `fanout1` と `fanout2` という名前の 2 つのジョブが実行されます。 最後に、これらのジョブが完了すると、ジョブ `fanin` が実行されます。\n\n### ジョブ間の依存関係のAzure Pipelines構文\n\n```yaml\njobs:\n  - job: initial\n    pool:\n      vmImage: 'ubuntu-latest'\n    steps:\n      - script: echo \"This job will be run first.\"\n  - job: fanout1\n    pool:\n      vmImage: 'ubuntu-latest'\n    dependsOn: initial\n    steps:\n      - script: echo \"This job will run after the initial job, in parallel with fanout2.\"\n  - job: fanout2\n    pool:\n      vmImage: 'ubuntu-latest'\n    dependsOn: initial\n    steps:\n      - script: echo \"This job will run after the initial job, in parallel with fanout1.\"\n  - job: fanin\n    pool:\n      vmImage: 'ubuntu-latest'\n    dependsOn: [fanout1, fanout2]\n    steps:\n      - script: echo \"This job will run after fanout1 and fanout2 have finished.\"\n```\n\n### ジョブ間の依存関係の GitHub Actions 構文\n\n```yaml\njobs:\n  initial:\n    runs-on: ubuntu-latest\n    steps:\n      - run: echo \"This job will be run first.\"\n  fanout1:\n    runs-on: ubuntu-latest\n    needs: initial\n    steps:\n      - run: echo \"This job will run after the initial job, in parallel with fanout2.\"\n  fanout2:\n    runs-on: ubuntu-latest\n    needs: initial\n    steps:\n      - run: echo \"This job will run after the initial job, in parallel with fanout1.\"\n  fanin:\n    runs-on: ubuntu-latest\n    needs: [fanout1, fanout2]\n    steps:\n      - run: echo \"This job will run after fanout1 and fanout2 have finished.\"\n```\n\n詳しくは、「[GitHub Actions　のワークフロー構文](/ja/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idneeds)」をご覧ください。\n\n## タスクのアクションへの移行\n\nAzure Pipelinesでは、複数のワークフローで再利用できるアプリケーション コンポーネントである *tasks* を使用します。 GitHub Actions は\\_アクション\\_を使います。これは、タスクの実行とワークフローのカスタマイズに利用できます。 どちらのシステムでも、実行するタスクやアクションの名前を、必要な入力のキー/値のペアとともに指定できます。\n\n以下は、それぞれのシステムにおける構文の例です。\n\n### Azure Pipelinesのタスク構文\n\n```yaml\njobs:\n  - job: run_python\n    pool:\n      vmImage: 'ubuntu-latest'\n    steps:\n      - task: UsePythonVersion@0\n        inputs:\n          versionSpec: '3.7'\n          architecture: 'x64'\n      - script: python script.py\n```\n\n### アクションの GitHub Actions 構文\n\n```yaml\njobs:\n  run_python:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/setup-python@v5\n        with:\n          python-version: '3.7'\n          architecture: 'x64'\n      - run: python script.py\n```\n\nワークフローで使用できるアクションは [、GitHub Marketplace](https://github.com/marketplace?type=actions) にあります。または、独自のアクションを作成することもできます。 詳しくは、「[自動化の再利用](/ja/actions/creating-actions)」をご覧ください。"}