/
Using Sealights from a Jenkins Pipeline job
Using Sealights from a Jenkins Pipeline job
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.token.dev.cs', variable: 'SL_TOKEN')]) {
sh '''
echo -n "$SL_TOKEN" > sltoken.txt
echo "Downloading Sealights 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"
'''
}
writeFile file: 'slmaven.json', text: '''\
|{
| "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": "",
| "includeResources": true,
| "testStage": "Unit Tests",
| "sealightsJvmParams": {},
| "proxy": null,
| "logEnabled": false,
| "logDestination": "console",
| "logLevel": "off"
|}
'''.stripMargin().stripIndent()
script {
if (true) {
// Define SCM details
env.scmOnPremProvider = "github"
env.scmOnPremBaseUrl = "https://github.com/marcsealights/java-gps-calorie-calculator/blob/"
env.scmOnPremVersion = '2.19.0' // Adjust as necessary
// Dynamically set SCM version if needed
// env.scmOnPremVersion = sh(script: 'curl -sI https://github.mycompany.com/api/v3 | grep Version | awk \'{print $2}\' | tr -d \'\\r\'', returnStdout: true).trim() //github
// env.scmOnPremVersion = sh(