TeamCity Pipelines Help

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.

Single-Job Pipeline

Create a Maven Step

  1. 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.

    New pipeline
  2. 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.

    Choose a repository
  3. 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.

    Open step settings
  4. In Step settings, enter the mvn -B -DskipTests clean package as the script content.

  5. 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.

    Switch from Script to Maven
    Switch from Script to Maven Result
  6. 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).

    Pipeline Failed Build Log

    To fix this issue, go back to Pipeline settings, click Show all options and choose "Maven 3.8.6" in the Maven version field.

  7. 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.

  1. In Job settings, add the second Step.

    Add Step 2
  2. Type mvn test in the Script content field and ignore the suggestion to switch from Script runner to Maven.

    Script step settings
  3. 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.

    Run in Docker Container
  4. 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.

name: Sample Java App Maven jobs: Job 1: steps: - type: maven goals: '-B -DskipTests clean package' maven-version: bundled_3_8 - type: script script-content: mvn test docker-image: maven:3.9.0-eclipse-temurin-11 runs-on: Linux-Medium
Last modified: 18 March 2024