fbpx

How To Deploy AppVeyor Build API And PowerShell? With 1 Best Example

AppVeyor is a cloud-based continuous integration system that lets CI configuration files coexist with your projects and connects natively with your source control.

You may generate releases, push the packaged applications to the integrated Octopus repository, and automatically package your applications from your source control repository using AppVeyor.

How To Deploy AppVeyor Build API And PowerShell

Learn how to set up continuous delivery for a solution that consists of an ASP.NET web application and a Windows service using PowerShell remote access and AppVeyor CI in this post.

What is AppVeyor?

AppVeyor is a cloud-based continuous integration and delivery (CI/CD) platform specifically designed for building and deploying software applications. It provides a robust set of tools and features to automate the build, test, and deployment processes of software projects. It supports a wide range of programming languages and integrates with popular version control systems such as GitHub, Bitbucket, and GitLab.

With AppVeyor, developers can set up automated workflows to build their applications from source code, run tests to ensure code quality and deploy the application to various environments. The platform supports both Windows and Linux environments, allowing developers to target multiple platforms and architectures.

AppVeyor offers various features to streamline the development and release process. It provides a web-based dashboard where users can configure their projects, define build configurations, and manage deployment settings. The platform supports parallel and concurrent builds, enabling faster feedback cycles and reducing development time. It also integrates with popular testing frameworks and tools, allowing developers to run unit tests, integration tests, and other automated tests as part of the build process.

Furthermore, AppVeyor integrates with artifact repositories, making it easy to store and manage built binaries, documentation, and other artifacts. It offers options for deployment to various hosting services, cloud platforms, and package managers, enabling seamless delivery of applications to end users or other environments.

Overall, AppVeyor simplifies the process of building, testing, and deploying software applications, providing developers with a powerful CI/CD platform to streamline their development workflows and deliver high-quality software efficiently.

Three build scenarios are available from AppVeyor:

  • Visual Studio solution: MSBuild is executed against the VS.NET solution or project file by the Visual Studio solution (look for the first.sln or.*proj if not specified), and the build results of all projects are packaged as artifacts.
  • MSBuild: Run MSBuild at your discretion with the ability to define unique build artifacts on the “Packaging” tab.
  • Script: Runs a batch file or PowerShell script that has been supplied. provide the most control over the build process and its outcomes.

PowerShell authentication for the AppVeyor API

Find the AppVeyor API token by clicking the arrow in the top-right corner of the screen, then select My Profile. 
After selecting the API keys on the left, select the dropdown in the center. 

  • While the option uses the v1 API, the All Accounts option uses the v2 API.
  • While the v1 option only has power over one account, the v2 option has total control over all accounts.
  • Make sure that All accounts are selected in the menu.
  • The API key will then appear as the Bearer token.

You must navigate to the PowerShell editor. 

  • My AppVeyor account name ($accountName), varies based on whether you’re utilizing an on-prem or cloud environment.
  • The $apiUrl, stands for the API endpoint that each call will reference. As you can see, I’ve defined both the cloud-based and on-premises tokens because they differ depending on the platform you use.
  • The Appveyor API token is duplicated from the previous ($authToken) line with distinct references for use on-premises and in the cloud.
  • A PowerShell hashtable ($authHeaders) with the proper keys and values to give to the API
## Cloud
# $cloudAccountName = 'Dummy'
# $apiUrl = "https://ci.appveyor.com/api/account/$cloudAccountName"
# $authToken = 'v2.XXXXXXXXXXX'
## On-prem
$onPremAccountName = 'AppVeyor'
$apiUrl = "http://localhost:8050/api/account/$onPremAccountName"
$authToken = 'v2.XXXXXXXXX'
$authHeaders = @{
    "Authorization" = "Bearer $authToken"
    "Content-type"  = "application/json"
}
PowerShell authentication for the AppVeyor API

Using the AppVeyor API in PowerShell

It’s time to query the API to see if we can get anything back once you’ve set up your token and all of your common variables. I’ll do a test using the Get Projects endpoint (appveyor.com). All of the projects that you have created in your AppVeyor account are returned by this endpoint.

Use the Invoke-RestMethod (microsoft.com) PowerShell cmdlet to call an API. That is already available because you built the headers above ($authHeaders) before. The URI to call is then required.

You can concatenate the base URI with the right endpoint, in this case /projects, by using the $apiUrl mentioned before. You will then be given the URI to query. Additionally, providing the just-created headers hashtable will create a command reference to query every project you have in your account.

$getProjectsUri = "$apiUrl/projects"
Invoke-RestMethod -Uri $getProjectsUri -Headers $authHeaders
PowerShell authentication for the AppVeyor API