Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 17 Next »

Using a Sealights Token defined in Jenkins Credentials

You can define an entry in your Jenkins Credentials to store your Agent token and use it in your pipeline script.

You can refer to it from your script as follow

withCredentials([string(credentialsId: 'sl.agent.token.dev.cs', variable: 'SL_TOKEN')]) {
  sh '''
  echo -n "$SL_TOKEN" > sltoken.txt
  '''
}

Sample script for Maven integration (Java Agent)

pipeline {
    agent any

    tools {
      jdk '1.8'
    }
    
   stages {
       
        stage('Git') {
            steps {
                // Wipe out workspace
                cleanWs()

                // Get some code from a GitHub repository
                git 'https://github.com/marcsealights/java-gps-calorie-calculator.git'
            }
        }       
       
       stage ("Adding Sealights") {
            steps {
            
                withCredentials([string(credentialsId: 'sl.agent.token', variable: 'SL_TOKEN')]) {
                  sh '''
                  echo -n "$SL_TOKEN" > sltoken.txt

                  echo "Downloading Sealights Latest Agent..."
                  wget -nv https://agents.sealights.co/sealights-java/sealights-java-latest.zip
                  unzip -oq sealights-java-latest.zip
                  echo "Local agent version is now:" `cat sealights-java-version.txt` "\n"
                  '''
                }
                
                script {
                    sh '''
                    echo  '{
                        "executionType": "full",
                        "tokenFile: "sltoken.txt",
                        "createBuildSessionId": true,
                        "appName": "${env.JOB_NAME}",  
                        "branchName": "${env.BRANCH_NAME}",
                        "buildName": "${env.BUILD_NUMBER}", 
                        "packagesIncluded": "*info.puzz.*",  //Specific to your app
                        "packagesExcluded": "",
                        "filesIncluded": "*.class",
                        "filesExcluded": "*test-classes*",
                        "recursive": true,
                        "includeResources": true,
                        "testStage": "Unit Tests",
                        "labId": null,
                        "logEnabled": false,
                        "logDestination": "console",
                        "logLevel": "off",
                        "logFolder": "/tmp",
                        "sealightsJvmParams": {},
                        "enabled": true
                     }' > slmaven.json

                    echo "Updating POM with Sealights..."
                    java -jar sl-build-scanner.jar -pom -configfile slmaven.json -workspacepath .
                 ''' 
                }
            }
        }
       
      stage('Build') {
            steps {
                // Run Maven with regular command
                sh "mvn clean package"
         }
      }
   }
}

  • No labels