
Azure Travis is a powerful tool for automating software builds, tests, and deployments. It's a free open-source platform that integrates seamlessly with Azure, allowing developers to focus on writing code rather than managing infrastructure.
With Azure Travis, you can automate your Continuous Integration and Deployment (CI/CD) pipeline, which means your code is built, tested, and deployed automatically whenever changes are pushed to the repository. This saves time and reduces the risk of human error.
Azure Travis supports a wide range of programming languages, including Python, Java, and Node.js.
Configuring Builds
By default, both Travis and Azure Pipelines perform CI builds on all branches. You can limit these builds to specific branches in Azure Pipelines by listing the branches to build in the include list and the branches not to build in the exclude list, with wildcards supported.
To build only the main branch and those that begin with the word "releases", you would list the main branch and the "releases" branches in the include list, and any other branches you want to exclude in the exclude list.
Azure Pipelines offer a feature-rich configuration for builds, allowing you to orchestrate your entire deployment workflow from a single YAML file in your repository.
YAML Deployments
YAML Deployments are a game-changer for configuring builds.
Storing your configuration as code in YAML makes your code self-documenting, repeatable, and versioned. This is because YAML is a human-readable format that can be easily understood and modified.
You can define your entire deployment workflow in a single YAML file in your repository, which is a big improvement over the old UI-based approach.
The benefits of YAML deployments include easily deploying to any number of environments, identifying environments that require manual approval, and automating change management approval workflow integration with JIRA.
Here are some key features of YAML deployments:
- Easily deploy to any number of environments (i.e. dev and prod, or dev, test and prod, etc)
- Identify environments that require manual approval
- Automated change management approval workflow integration with JIRA through Azure Pipelines Environment checks
- Integrated governance and validation of service metadata against a central registry
- Contextual platform variables based on the deployment environment
- Integrated semantic versioning model(s)
- Integrated pull request context and variables
- Enforced security checks for Git branches to be protected, certain names, required templates before deploying to production
- Filtered custom task list to remove or identify any improper or insecure usage
- Update organizational templates to affect all pipelines
These features make YAML deployments a powerful tool for configuring builds and deployments.
Language
Language is a crucial aspect of configuring builds, and it's essential to understand how to specify the language and its version. You can use the language keyword in your build configuration file to identify the prerequisite build environment.
Travis and Azure Pipelines handle language specifications differently. In Travis, the language keyword implies both the version of language tools to be used and the build steps to be performed. On the other hand, in Azure Pipelines, you need to specify the commands that you want to run.
Some languages, like Node.JS, can be selected using the language keyword in the Azure Pipelines configuration file. For example, to select Node.JS 16.x, you can use the following line in your azure-pipelines.yml file: Node.JS 16.x.
Here's a breakdown of language mappings for some commonly used languages:
For less common languages, you might need to use additional commands or install dependencies. For example, to enable Crystal, you need to install the Crystal language and then run the shards install command.
Building Specific Branches
Building specific branches allows you to control which branches trigger a build.
By default, both Travis and Azure Pipelines perform CI builds on all branches.
You can limit these builds to specific branches, which is useful for teams that only need to test certain branches.
In Azure Pipelines, the list of branches to build should be listed in the include list.
Wildcard support means you can easily include multiple branches at once, like branches that start with a specific word.
For example, to build only the main branch and those that begin with the word "releases", you would list "main" and "releases*" in the include list.
The branches not to build should be listed in the exclude list.
This allows you to exclude certain branches, like those that start with "dev" or "feature".
Build Process
Building a CI/CD pipeline with Azure and Travis CI is a straightforward process.
You can start by creating a new GitHub repository and adding a `.travis.yml` file to specify the build process.
Azure provides a simple way to connect your GitHub repository to Travis CI.
The `.travis.yml` file is where you define the build process, including the language, version, and any dependencies required.
Travis CI will automatically detect the language and version specified in the `.travis.yml` file.
You can also use Azure's built-in support for Docker to create a containerized build environment.
The containerized build environment provides a consistent and reproducible build process.
Azure's integration with Travis CI allows you to trigger builds automatically whenever code is pushed to your repository.
This ensures that your code is always built and tested before it's deployed to production.
By following these steps, you can easily set up a CI/CD pipeline with Azure and Travis CI.
Handling Results
You can configure Azure Pipelines to run jobs based on the success or failure of previous jobs or environment variables, giving you a flexible set of dependencies and conditions for flow control.
With Azure Pipelines, you can define jobs to always run, regardless of the success of other jobs. This is useful for running scripts that are essential to your build process.
In contrast, Travis allows you to specify steps that run when the build succeeds, using the after_success phase, or when the build fails, using the after_failure phase. This gives you more control over your pipeline's flow.
Azure Pipelines enables more flexible and powerful pipelines by allowing you to define success and failure conditions based on the result of any step. This is a significant advantage over Travis' more limited approach.
Environment Variables
Environment Variables are used to store and retrieve configuration values in Azure Travis builds. They can be set at the repository level or at the build level.
You can set environment variables in the repository settings, and they will be available to all builds in that repository. This is useful for storing values that are common to all builds, such as API keys or database connections.
Environment variables can also be set at the build level, using the `env` keyword in the `.travis.yml` file. This allows you to set variables that are specific to a particular build.
Azure Travis has a concept of "secure" environment variables, which are stored encrypted and can only be accessed in the build environment. These variables are useful for storing sensitive information, such as API keys or database passwords.
You can reference environment variables in your build scripts using the `${VARIABLE_NAME}` syntax. This allows you to access the value of the variable and use it in your build process.
Advanced Build Options
Azure Travis allows you to customize your build environment with advanced options.
You can specify a custom Docker image to use for your build, which is useful for building and testing applications that require specific dependencies.
Azure Travis also supports multiple build environments, allowing you to test your application on different platforms and configurations.
This feature is particularly useful for cross-platform applications that need to be tested on Windows, macOS, and Linux.
Language Mappings
Language mappings can be a bit tricky to understand, but don't worry, I've got you covered. The language keyword in Azure Pipelines is used to specify the language and version you want to use for your build.
For most languages, you can simply use the language keyword and Azure Pipelines will automatically execute the necessary commands for you. For example, if you want to use Node.js 16.x, you can simply use the language keyword and Azure Pipelines will take care of the rest.
Here's a list of some of the most commonly used languages and the commands that are executed automatically:
Keep in mind that some languages require additional steps or dependencies to be installed. For example, if you want to use Crystal, you'll need to use a Docker container and install the necessary dependencies.
Parallel Jobs
Parallel jobs allow you to run multiple tasks simultaneously, making your build process more efficient.
Travis provides parallelism by letting you define a stage, which is a group of jobs that are executed in parallel.
With Azure Pipelines, you can make each step or stage dependent on any other step, specifying which steps run serially and which can run in parallel.
You can fan out with multiple steps running in parallel after the completion of one step, and then fan back in with a single step that runs afterward.
For example, you can run a build script, then upon its completion run both unit tests and integration tests in parallel, and once all tests have finished, package the artifacts and then run the deploy to pre-production.
Sources
- https://travis.media/blog/pass-the-azure-az-104-certification/
- https://www.linkedin.com/posts/robertst_azure-files-share-with-nfs-a-step-by-step-activity-7246549408568205314-79hw
- https://webhint.io/docs/user-guide/development-flow-integration/travis-and-azure/
- https://travisgosselin.com/sps-commerce-azure-pipelines-a-ci-cd-journey/
- https://learn.microsoft.com/en-us/azure/devops/pipelines/migrate/from-travis
Featured Images: pexels.com