Some benefits of running Linux builds on AppVeyor:
sudo
access to VM running buildTo run your build on Ubuntu
image either add the following line to your appveyor.yml
:
image: Ubuntu
or if you don’t use appveyor.yml
select Ubuntu
image on Environment tab of AppVeyor project settings.
You can also put project configuration in
.appveyor.yml
dot-file in the root of your repo. AppVeyor searches repo forappveyor.yml
first and then for.appveyor.yml
.
init
scripts/etc/hosts
fileinstall
scripts.csproj
and AssemblyInfo.cs
fileson_success
scriptson_failure
scripts (if the build has failed)on_finish
scriptsBelow is a minimal appveyor.yml
to test Node.js project:
image: Ubuntu
install:
- npm install
test_script:
- npm test
build: off
build
phase should be off as, by default, it’s set toMSBuild
mode for automatic discovery and building of .NET Core projects (see the section below).
You can use both Bash and PowerShell commands simultaneously to control the build flow.
To run Bash command either put it with sh:
prefix or without it, for example the following two commands will be run in Bash shell:
install:
- ls -al
- sh: sudo apt-get update
To run command in PowerShell session use ps:
or pwsh:
prefixes, for example:
test_script:
- ps: Write-Host "Hello, world!"
AppVeyor keeps the same Bash and PowerShell shells for the duration of the build and all commands run in the same context. That means, for example, that local variable defined on install
stage is available on later stages:
init:
- ps: $my_variable = 'Test value'
test_script:
- ps: Write-Host "This is $my_variable"
AppVeyor exchanges environment variables and current directory between Bash and PowerShell shells. Environment variable defined in Bash command is immediately available in PowerShell command next to it and vice versa:
install:
- MY_VAR=test
- ps: $env:MY_VAR
Environment variable names are case-sensitive on Linux platform.
false
command in Bash “gracefully” terminates the build with “red” status by running on_failure
and on_finish
commands.
throw "some error message"
statement in PowerShell “gracefully” terminates the build with “red” status by running on_failure
and on_finish
commands.
exit 0
in Bash immediately terminates the build with “green” status; without running on_success
and on_finish
commands.
exit <non-zero>
in Bash immediately terminates the build with “red” status without running on_failure
and on_finish
commands.
appveyor exit
in Bash “gracefully” terminates build with “green” status by running on_success
and on_finish
commands.
Exit-AppveyorBuild
in PowerShell “gracefully” terminates build with “green” status by running on_success
and on_finish
commands.
AppVeyor for Linux provides a new stack
definition for quick configuration of languages and services used by your build/tests:
stack: <language|service> [version], <language|service> [version], ...
For example, to enable the latest Node.js 9.x and MySQL add this to your appveyor.yml
:
stack: node 9, mysql
The following languages can be configured in stack
:
node <version>
- select Node.jsgo <version>
- Golangruby <version>
- Rubyjdk <version>
- Javapython <version>
- PythonThe following services can be configured in stack
:
docker
mongodb
mssql
mysql
postgresql
(or pgsql
)rabbitmq
redis
Build phase could be either your own scripts, be enabled to build .NET Core project(s) or be turned off.
For your own scripts use build_script
section, for example:
build_script:
- mvn install
For automated building .NET Core projects please see “.NET Core support” section below.
To disable build phase completely put this:
build: off
Test phase could be either your own scripts, be enabled to discover and test .NET COre project(s) or be turned off.
For your own scripts use test_script
section, for example:
test_script:
- npm test
For automated testing of .NET Core projects please see “.NET Core support” section below.
To disable test phase completely put this:
test: off
You can use the same appveyor.yml
to control builds running on both Windows and Linux platforms.
First, start from adding a matrix of build images. For example, to run build on both Visual Studio 2015
and Ubuntu
images add the following:
image:
- Visual Studio 2015
- Ubuntu
With matrix you can specialize configuration for different jobs or keep flat configuration using approaches described below.
Prefix command with cmd:
to run it on Windows image only:
- cmd: echo Hey, I'm displayed on Windows only!
Prefix command with sh:
to run it on Linux image only:
- sh: printf "I'll be shown on Linux!"
Do not prefix command to run it on both Windows and Linux. You have to make sure the command is good for both Windows batch files and Bash:
- dir
- echo I'm running on both Windows and Linux!
PowerShell commands prefixed with ps:
and pwsh:
(on Linux they both run as PowerShell Core) run on both Windows and Linux, however you can distinguish between platforms by using the following PowerShell variables:
$isLinux
is $true
on Linux$isWindows
is $true
on WindowsFor example, the following command will print different message for the same build running on Windows and Linux:
- ps: |
if ($isLinux) {
Write-Host "This is Linux!"
} else {
Write-Host "This is NOT a Linux!"
}
AppVeyor also introduces two new environment variables defining platform:
CI_WINDOWS
is true
if the build is running on Windows-based image; otherwise false
.CI_LINUX
is true
if the build is running on Linux-based image; otherwise false
.You can use these environment variables in bash, Bash and PowerShell commands.
Also, there APPVEYOR_YML_DISABLE_PS_LINUX
tweak environment variable that disables execution of PowerShell commands on Linux-based images, for example:
environment:
APPVEYOR_YML_DISABLE_PS_LINUX: true
install:
- ps: Write-Host "This command won't be run on Linux"
- sh: printf "This command will be run on Linux only"
Ubuntu build workers have Docker service pre-installed.
To enable Docker add this line to appveyor.yml
:
services:
- docker
Then you can use Docker in your build, for example:
test_script:
- docker run hello-world
AppVeyor for Linux has built-in first-class support for building, testing, packaging and deploying .NET Core applications and libraries.
To enable automatic discovery and building of .NET Core solution add to appveyor.yml
:
build:
verbosity: minimal
The construction above will make AppVeyor looking for .sln
file in the root of the repository first and then recursively in sub-directories.
To specify direct path to .sln
or .csproj
file add:
build:
project: MySolution.sln
verbosity: minimal
By default, AppVeyor uses the latest .NET Core SDK installed to build the project, however you can pin-point exact version of SDK with global.json file in the root of your repo.
Build configuration (Debug
or Release
) can be specified as:
configuration: Release
Similarly to patching version attributes in AssemblyInfo.*
files AppVeyor for Linux can patch <Version>
elements in .csproj
files. To enable .csproj
file patching add:
dotnet_csproj:
patch: true
file: '**\*.csproj'
version: '{version}'
package_version: '{version}'
assembly_version: '{version}'
file_version: '{version}'
informational_version: '{version}'
Note that
<Version>
and other version-related elements should exist already in.csproj
file - AppVeyor won’t add them for you.
AppVeyor provides automatic packaging for the following types of .NET Core projects:
You can enable automatic packaging by adding this to appveyor.yml
:
build:
project: MySolution.sln
publish_nuget: true
publish_aspnet_core: true
publish_core_console: true
verbosity: minimal
NuGet packages will be automatically published to account and project NuGet feeds.
Both ASP.NET Core and .NET Core console projects will be published to .zip
files and pushed to build artifacts. You can deploy them later with one of the supported deployment methods described below.
By default, if you omit test
section in appveyor.yml
AppVeyor will assume Auto
mode working in pair with MSBuild
build mode. In Auto
mode AppVeyor will run tests against all test projects found in the solution.
With AppVeyor for Linux you can test your ASP.NET Core applications on Linux platform with SQL Server 2017 for Linux.
To start SQL Server 2017 for Linux service add this to your appveyor.yml
:
services:
- mssql
SQL Server 2017 instance details:
localhost
Password12!
sqlcmd
command line is available to execute commands against SQL Server instance. For example, to print SQL Server version use this:
init:
- sqlcmd -S localhost -U SA -P Password12! -Q 'select @@VERSION'
There is an article about how to access Linux build worker via SSH.
Build cache works the same as for Windows build workers.
Packaging artifacts works the same as for Windows build workers.
AppVeyor Build Agent for Linux has similar deployment functionality as on Windows.
The following deployment providers are currently supported by AppVeyor for Linux: