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.
Click any repository from the list. In this tutorial, I use the following sample repository with a simple Java app and unit tests for it: Sample Java App with Maven.
Once you choose a repository, TeamCity creates a new Pipeline with an empty Job. Click this Job to select it, and click Add... under the Steps section to add a new Step.
Save and run your Pipeline. 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.xmlfile (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.
You can choose the "Maven" Step type and set it up similarly to the first step, but for now choose "Script" instead. This Step type allows you to run any custom scripts the target OS supports.
mvn testin the Script content field. TeamCity is smart enough to detect a Maven command, and suggests to convert this Step from "Script" to "Maven". Ignore this suggestion and keep the "Script" Step.
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 help of Maven version field available for "Maven" Steps. "Script" Steps do not have this option, so we need to use a different 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
Save and run the Pipeline. Both Steps should now be able to finish successfully.
The final Pipeline should have the following YAML configuration. You can go to Pipeline settings, click the Preview YAML button in the top right corner, and compare your current settings with this reference configuration to check whether some of your settings are missing or have different values.