Using MSYS2 in CI
Github Actions (recommended)
Assuming you use GitHub this is the easiest way to get going. We provide aGitHub Action which handles everything from installing the latest MSYS2,updating it and installing all the packages you need. All you have to do is toprovide a BASH script that runs your code in the MSYS2 environment.
1) Create a workflow file, for example.github/workflows/msys2.yml, seethe GitHub docs for more details
2) Paste the following into your workflow file:
name:MSYS2on:[push,pull_request]jobs:msys2-ucrt64:runs-on:windows-latestdefaults:run:shell:msys2 {0}steps:-uses:actions/checkout@v5-uses:msys2/setup-msys2@v2with:msystem:UCRT64update:trueinstall:git mingw-w64-ucrt-x86_64-gcc-name:CI-Buildrun:|echo 'Running in MSYS2!'./ci-build.shFor more details on the 'msys2/setup-msys2' action and all the available optionsseehttps://github.com/marketplace/actions/setup-msys2
GitLab
GitLab offersshared Windows runnerswith somepre-installed softwareand you can build a project using the following.gitlab-ci.ymlsnippet, which illustrates how to build a regular autotools-basedproject. SeeGitLab's CI/CD documentationfor general reference on CI/CD in GitLab.
Windows-MSYS2-UCRT64:# https://docs.gitlab.com/ci/runners/hosted_runners/windows/tags:[saas-windows-medium-amd64]script:# https://www.msys2.org/docs/ci/#gitlab-wget.exe -nv -O msys2.exe https://github.com/msys2/msys2-installer/releases/download/2025-02-21/msys2-base-x86_64-20250221.sfx.exe# https://github.com/msys2/msys2-installer/releases/download/nightly-x86_64/msys2-base-x86_64-latest.sfx.exe-Get-FileHash ./msys2.exe -Algorithm SHA256 | Format-List-./msys2.exe -y -oC:\-Remove-Item msys2.exe-$env:CHERE_INVOKING = 'yes'-$env:MSYSTEM = 'UCRT64'# https://www.msys2.org/docs/environments/-C:\msys64\usr\bin\bash -lc ' '-C:\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu'-C:\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu'-|C:\msys64\usr\bin\bash -lcx 'pacman --noconfirm -Syu git mingw-w64-ucrt-x86_64-autotools mingw-w64-ucrt-x86_64-gcc./bootstrap./configuremake V=1 check VERBOSE=t'-C:\msys64\usr\bin\bash -lc 'grep ^PASS tests/basic.log'Appveyor
Appveyor provides a MSYS2 installation on all their images underC:\msys64,seehttps://www.appveyor.com/docs/windows-images-software/
Make sure to use theVisual Studio 2019 image or newer, as the MSYS2installation on older images is outdated and updating there no longer works.
In case you want to update the MSYS2 installation and install packages you needto update MSYS2 first. For this you need to run the following commands:
# Update MSYS2C:\msys64\usr\bin\bash-lc"pacman --noconfirm -Syuu"# Core update (in case any core packages are outdated)C:\msys64\usr\bin\bash-lc"pacman --noconfirm -Syuu"# Normal update# Then run your code$env:CHERE_INVOKING='yes'# Preserve the current working directory$env:MSYSTEM='UCRT64'# Start a 64 bit Mingw environmentC:\msys64\usr\bin\bash-lc"./ci-build.sh"Docker
Install MSYS2 underC:\msys64 into a Windows based Docker image:
# select as base image matching your host to get process isolationFROMmcr.microsoft.com/windows/servercore:2004SHELL["powershell","-Command","$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]RUN[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;\Invoke-WebRequest-UseBasicParsing-uri"https://github.com/msys2/msys2-installer/releases/download/nightly-x86_64/msys2-base-x86_64-latest.sfx.exe"-OutFilemsys2.exe;\.\msys2.exe-y-oC:\;\Remove-Itemmsys2.exe;\functionmsys(){C:\msys64\usr\bin\bash.exe@('-lc')+@Args;}\msys' ';\msys'pacman --noconfirm -Syuu';\msys'pacman --noconfirm -Syuu';\msys'pacman --noconfirm -Scc';Other Systems
On systems that don't provide MSYS2 integration you need to install and updateMSYS2 yourself.
1) Download and install MSYS2. For CI systems we provide a self extracting archive, so you don't need any additional tools.
# Download the archive(New-ObjectSystem.Net.WebClient).DownloadFile('https://github.com/msys2/msys2-installer/releases/download/nightly-x86_64/msys2-base-x86_64-latest.sfx.exe','msys2.exe').\msys2.exe-y-oC:\# Extract to C:\msys64Remove-Itemmsys2.exe# Delete the archive again2) Run MSYS2 for the first time and update it
# Run for the first timeC:\msys64\usr\bin\bash-lc' '# Update MSYS2C:\msys64\usr\bin\bash-lc'pacman --noconfirm -Syuu'# Core update (in case any core packages are outdated)C:\msys64\usr\bin\bash-lc'pacman --noconfirm -Syuu'# Normal update3) Run your code (ci-build.sh in this case)
$env:CHERE_INVOKING='yes'# Preserve the current working directory$env:MSYSTEM='UCRT64'# Start a 64 bit Mingw environmentC:\msys64\usr\bin\bash-lc'./ci-build.sh'FAQ
My CI system doesn't exit at the end of the run and hangs. What's wrong?
In some cases CI systems will wait until all processes you have started havealso ended, but the MSYS2 setup and update might spawn processes for gnupg etc.that will stay around in the background forever. To end them all you can run:
taskkill/F/FI"MODULES eq msys-2.0.dll"MSYS2 fails to update on Appveyor with some "key is unknown" error. What's wrong?
The MSYS2 installation on older Appveyor images hasn't been updated in years andis no longer supported. Either use theVisual Studio 2019 image or newer, orinstall MSYS2 manually as described above.