Create a Single-Job Pipeline
This tutorial demonstrates how to create a Pipeline with one Job and two Steps. Both steps utilize Maven to build and test the sample solution.
Create a Maven Step
Click New Pipeline... and wait for TeamCity to use the OAuth connection you provided to scan a VCS and display the list of available repositories.
Fork the Sample Java App with Maven repository (contains a simple Java app and unit tests for it) and choose your fork from the repositories list.
Once you choose a repository, TeamCity creates a new Pipeline with an empty Job. Click this Job to select it, and expand the empty Step 1.
In Step settings, enter the
mvn -B -DskipTests clean package
as the script content.TeamCity detects that you entered Maven commands, and suggests switching to a dedicated runner that allows you to specify a path to POM file, choose the required Maven version, enable parallel tests, and more. Click the corresponding link to convert your Script runner to Maven.
Click Save and Run. You will be redirected to the build results page with detailed information about this run.
Our sample Pipeline failed on its first launch because the Maven version on a build agent is different from the version specified in the app's
pom.xml
file (the <version>[3.8.6,)</version< line).To fix this issue, go back to Pipeline settings, click Show all options and choose "Maven 3.8.6" in the Maven version field.
Run the Pipeline again and ensure it finishes correctly.
Add a Script Step
Our first step skipped all unit tests. We can add the second Step to test the project after the first Step finishes.
In Job settings, add the second Step.
Type
mvn test
in the Script content field and ignore the suggestion to switch from Script runner to Maven.If you attempt to run the Pipeline now, Step 2 will run into the same problem as Step 1 did: Maven version mismatch. In Step 1, we solved this issue with the specialized Maven version setting available for the Maven runner. The generic Script runner does not feature this options, and we need to use another solution.
Enable the Run in Docker option and specify the Docker Image name in the field below. These options allow you to run your Step inside a Docker container. Use this technique when you need a software that isn't installed on any of available agents. For example, if you require the latest Maven 3.9, you can run your Step in the
maven:3.9.0-eclipse-temurin-11
container.Save and run the Pipeline. Both Steps should now be able to finish successfully.
YAML Configuration
The final Pipeline should have the following YAML configuration. You can go to Pipeline settings, switch the editing mode from Visual to YAML, and compare your current settings with this reference configuration to check whether some of your settings are missing or have different values.