# Jenkins Plugin: Teamscale Upload

For the CI/CD-pipeline in your Jenkins server you can make use of the teamscale-upload plugin. The purpose of this plugin is to upload external reports like code coverage from your builds to your Teamscale server. The showcases in this documentation cover a freestyle project, declarative pipeline and scripted pipeline of Jenkins.

# Freestyle Project

  1. Install the plugin from the official marketplace on your Jenkins server
  2. Create a freestyle project in Jenkins
  3. In the Source Code Management step of your freestyle project, explicitly specify the branch which is cloned, so the plugin works correctly.
  4. Add the Teamscale Upload plugin as post-build action
  5. Configure the plugin
    Post Build Step
  • URL: The URL to your Teamscale server
  • Credentials: Select Jenkins global credentials consisting of Teamscale Username and IDE Access Key (from http://<your-teamscale-url>/admin.html#users//?action=edit&username=<your-build-user>). In the Jenkins Credentials Provider, use Username with password for storing this information.
  • Project: The project in Teamscale to upload the data to.
  • Partition: The partition in Teamscale.
  • Upload Message: Desired message for the data which will be uploaded.
  • Include Pattern: Include pattern for file selection in the Jenkins working directory (e.g. here: selecting all *.simple files in working directory)
  • Report Format ID: Use the PARAMETER VALUE in supported formats.
  • Revision: Please leave this one empty! Only needed for the pipeline build steps.

Multiple File Formats and/or Report Format Ids

The plugin is only supporting one file format and one report format. If you do look for multiple steps please have a look at the pipelines.

# Declarative Pipeline

Further reading at the official Jenkins declarative pipeline documentation.

pipeline {
    agent any
    
    stages {
         stage('Stage 1') { 
            steps {
                // Checkout is mandatory to set ENV variable GIT_COMMIT in the pipeline
                git 'https://github.com/Test/test.git'
                // For SVN, change GIT_COMMIT to SVN_REVISION
                teamscale includePattern: '**/*.simple', credentialsId: 'teamscale_id', partition: 'yourPartition', reportFormatId: 'SIMPLE', teamscaleProject: 'simpleProject', uploadMessage: 'yourMessage', url: 'http://localhost:8100', revision: "${GIT_COMMIT}"
            }
        }

         stage('Stage 2') {
            steps {
               teamscale includePattern: '**/*.simple', credentialsId: 'teamscale_id', partition: 'yourPartition', reportFormatId: 'SIMPLE', teamscaleProject: 'simpleProject', uploadMessage: 'yourMessage', url: 'http://localhost:8100', revision: "${GIT_COMMIT}"
               teamscale includePattern: '**/*.xml', credentialsId: 'teamscale_id', partition: 'yourPartition', reportFormatId: 'JACOCO', teamscaleProject: 'jacocoProject', uploadMessage: 'yourMessage', url: 'http://localhost:8100', revision: "${GIT_COMMIT}"
            }
        }
    }
    post { 
            always {
                teamscale includePattern: '**/*.simple', credentialsId: 'teamscale_id', partition: 'yourPartition', reportFormatId: 'SIMPLE', teamscaleProject: 'simpleProject', uploadMessage: 'yourMessage', url: 'http://localhost:8100', revision: "${GIT_COMMIT}"
                teamscale includePattern: '**/*.xml', credentialsId: 'teamscale_id', partition: 'yourPartition', reportFormatId: 'JACOCO', teamscaleProject: 'jacocoProject', uploadMessage: 'yourMessage', url: 'http://localhost:8100', revision: "${GIT_COMMIT}"
            }
    }
}

# Scripted Pipeline

Further reading at the official Jenkins scripted pipeline documentation.

node {
    def GIT_COMMIT

         stage('Stage 1') { 
                def rev = git 'https://github.com/Test/test.git'
                GIT_COMMIT = rev.GIT_COMMIT
        }

         stage('Stage 2') {
                teamscale includePattern: '**/*.simple', credentialsId: 'teamscale_id', partition: 'yourPartition', reportFormatId: 'SIMPLE', teamscaleProject: 'simpleProject', uploadMessage: 'yourMessage', url: 'http://localhost:8100', revision: "${GIT_COMMIT}"
                teamscale includePattern: '**/*.xml', credentialsId: 'teamscale_id', partition: 'yourPartition', reportFormatId: 'JACOCO', teamscaleProject: 'jacocoProject', uploadMessage: 'yourMessage', url: 'http://localhost:8100', revision: "${GIT_COMMIT}"
         }
}