Muistiinpano
Tämän sivun käyttö edellyttää valtuutusta. Voit yrittää kirjautua sisään tai vaihtaa hakemistoa.
Tämän sivun käyttö edellyttää valtuutusta. Voit yrittää vaihtaa hakemistoa.
Integrate the Modernize CLI into your CI/CD pipelines to automate application modernization at scale. This article shows you how to configure both GitHub Actions and Azure Pipelines to run the Modernize CLI on a schedule or on demand.
Running the Modernize CLI in a CI/CD pipeline enables you to:
- Automate upgrades on a recurring schedule without manual intervention.
- Standardize modernization workflows across your organization.
- Track changes through dedicated branches and build artifacts.
- Review results through pull requests, build summaries, and logs.
The sample pipelines in this article perform the following steps:
- Download and install the latest Modernize CLI.
- Run
modernize upgradewith a configurable target (for example,Java 21). - Commit any resulting changes and push them to a dedicated branch.
- Publish a results summary and upload CLI logs as build artifacts.
Prerequisites
- A GitHub Copilot subscription: Free, Pro, Pro+, Business, or Enterprise plan. See Copilot plans.
- A GitHub Personal Access Token (PAT): Create a token and store it as a repository secret named
GH_TOKEN. See Managing your personal access tokens.
Configure the pipeline
Create a workflow file at .github/workflows/modernize.yml in your repository with the following content:
name: Modernization CLI
on:
workflow_dispatch:
inputs:
upgrade_target:
description: 'Upgrade target (e.g., Java 21)'
required: false
default: 'latest'
schedule:
# Run during off-peak hours: 2 AM UTC daily
- cron: '0 2 * * *'
permissions:
id-token: write
contents: write
actions: read
jobs:
modernization:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Modernize CLI
run: |
curl -fsSL https://raw.githubusercontent.com/microsoft/modernize-cli/main/scripts/install.sh | sh
- name: Run Modernize CLI to upgrade code
run: |
TARGET="${{ github.event.inputs.upgrade_target }}"
if [ -z "$TARGET" ] || [ "$TARGET" = "latest" ]; then
modernize upgrade --no-tty
else
modernize upgrade "$TARGET" --no-tty
fi
- name: Push changes to result branch
id: push_changes
run: |
BRANCH_NAME="modernize-upgrade-${{ github.event.inputs.upgrade_target || 'latest' }}-$(date +%Y%m%d-%H%M%S)"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git reset .github/workflows
git diff --cached --quiet || git commit -m "chore: apply Modernize CLI changes [skip ci]"
git checkout -B "$BRANCH_NAME"
git push origin "$BRANCH_NAME"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_OUTPUT
- name: Display results summary
if: success()
run: |
cat >> $GITHUB_STEP_SUMMARY <<EOF
## Modernization Complete
### Branch Information
- **Result Branch**: \`${{ steps.push_changes.outputs.BRANCH_NAME }}\`
- **Target**: ${{ github.event.inputs.upgrade_target || 'latest' }}
### Links
- [View Branch](https://github.com/${{ github.repository }}/tree/${{ steps.push_changes.outputs.BRANCH_NAME }})
- [Create PR](https://github.com/${{ github.repository }}/compare/main...${{ steps.push_changes.outputs.BRANCH_NAME }})
EOF
- name: Upload Modernize CLI logs
if: always()
uses: actions/upload-artifact@v4
with:
name: modernize-logs
path: ~/.modernize/logs/
if-no-files-found: warn
Workflow details
The workflow includes two triggers:
- Manual dispatch (
workflow_dispatch): Run the workflow on demand from the Actions tab. Optionally specify an upgrade target such asJava 21. - Scheduled (
schedule): Run automatically at 2 AM UTC daily. Adjust the cron expression to match your preferred schedule.
Each run performs the following steps:
- Checks out the repository code.
- Downloads and installs the latest Modernize CLI.
- Runs
modernize upgradewith the specified target or defaults tolatest. - Commits any changes and pushes them to a timestamped branch.
- Writes a summary with branch and PR links to the GitHub Actions step summary.
- Uploads Modernize CLI logs as a build artifact for troubleshooting.
Note
The workflow resets .github/workflows before committing to avoid accidentally modifying the workflow file itself.
Run the pipeline
To trigger the workflow manually:
- Go to your repository on GitHub.
- Select the Actions tab.
- Select Modernization CLI from the workflow list.
- Select Run workflow.
- Optionally enter an upgrade target, and then select Run workflow to confirm.
After the workflow finishes, review the step summary for links to the result branch and create a pull request to merge the changes.
Troubleshooting
Common problems
Authentication errors:
- Verify the
GH_TOKENsecret or variable is set correctly with a valid GitHub Personal Access Token. - Ensure the token has the required scopes for GitHub Copilot access.
No changes detected:
- The Modernize CLI might determine that no changes are needed for the specified target.
- Review the uploaded logs artifact for details on the assessment.
Push failures (Azure Pipelines):
- Confirm the build service identity has Create branch, Contribute, and Read permissions on the repository.
- See Run Git commands in a script for detailed setup instructions.
Modernize CLI download errors:
- Verify the runner has internet access to https://github.com.
- Check for proxy or firewall restrictions that might block the download.