I am trying to learn how to use plot plugin, but I cannot figure out how to read some simple data from a csv file as the chart on the plot section is always empty. I have gone through several threads here in SO but I cannot find what my issue is. This would be the pipeline:
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo "test1"
}
}
stage('plot') {
steps{
plot csvFileName: 'data.csv', csvSeries: [[displayTableFlag: false, exclusionValues: '', file: 'data.csv', inclusionFlag: 'OFF', url: '']], description: 'this is a test plot', group: 'test', style: 'line', title: 'test1'
}
}
}
}
and this is the data from the data.csv file:
Alpha,Bravo,Charlie,Delta
1,2,5,20
Related
I have a build script I created which is located in a perforce streams depot at //HVS/Main/BuildScripts/hvs_client.jenkinsfile. However, when I run it it's just automatically successful. You can see in the image what it's doing.
I have set the Script Path to the correct location:
And I also have it setup with the correct stream path:
This exact setup works just fine on my windows server running jenkins. The only difference is that I'm trying to migrate my jenkins setup off of a physical machine and onto the cloud. The new master which is running on Ubuntu 20.04 is what is having these issues. I also have one "Node" which is a windows server which has the java agent installed and connected.
This is what my pipeline script looks like:
def channelId = 'removed_for_stackoverflow'
def threadId
def slackResponse
pipeline {
agent {label 'Windows'}
parameters {
choice(name: "BuildType", choices: ['Development', 'Shipping', 'Testing'], description: "What environment are you building to? Default is Development.")
string(name: "SevenZIPDir", defaultValue: "C:\\Program Files\\7-Zip\\7z.exe", description: "Location of 7zip executable.")
booleanParam(name: "clean", description: "Should jenkins clean the workspace?", defaultValue: false)
}
options {
skipDefaultCheckout()
}
stages {
stage('P4 Sync') {
steps {
script {
if (params.clean)
{
cleanWs()
}
p4sync charset: 'none', credential: '5feaca76-6a4a-4540-8a1e-e86ac8b3dc5b', populate: syncOnly(force: false, have: true, modtime: false, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true, revert: false), source: streamSource('//HVS/Main')
}
}
}
// https://github.com/jenkinsci/slack-plugin#bot-user-mode
// https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/VersioningAssetsAndPackages/
// https://www.perforce.com/manuals/jenkins/Content/P4Jenkins/variable-expansion.html
stage('Notify Slack users') {
steps {
script {
slackResponse = slackSend(channel: channelId, replyBroadcast: true, message: "Beginning build of ${env.JOB_NAME} for CL#${P4_CHANGELIST} ${env.BUILD_URL}")
threadId = slackResponse.threadId
slackResponse.addReaction("stopwatch")
}
}
}
stage('Build Client') {
steps {
retry(3) {
bat("%WORKSPACE%/Engine/Build/BatchFiles/RunUAT.bat BuildCookRun -project=\"%WORKSPACE%/HVS/HVS.uproject\" -noP4 -platform=Win64 -clientconfig=Development -cook -allmaps -clean -build -stage -pak -CrashReporter -archive -archivedirectory=\"%WORKSPACE%/temp/Development/x64\"")
}
}
}
/*stage('Deploy to Steam') {
}*/
stage('Archive Artifacts'){
steps {
dir("temp/${params.BuildType}/x64/WindowsNoEditor") {
bat "\"${params.SevenZIPDir}\" a -mx=1 -mmt=on %WORKSPACE%/temp/HVS_${params.BuildType}_x64_${P4_CHANGELIST}.7z *"
}
archiveArtifacts artifacts: "temp/*.7z", followSymlinks: false, onlyIfSuccessful: true
}
}
}
post {
success {
script {
slackSend(channel: threadId, replyBroadcast: true, message: "Build of ${env.JOB_NAME} for CL#${P4_CHANGELIST} successful! ${env.BUILD_URL}")
slackResponse.addReaction("white_check_mark")
}
}
failure {
script {
slackSend(channel: threadId, replyBroadcast: true, message: "Build of ${env.JOB_NAME} for CL#${P4_CHANGELIST} failed! ${env.BUILD_URL}")
slackResponse.addReaction("red_circle")
}
}
unstable {
script {
slackSend(channel: threadId, replyBroadcast: true, message: "Build of ${env.JOB_NAME} for CL#${P4_CHANGELIST} is not stable #channel ${env.BUILD_URL}")
slackResponse.addReaction("warning")
}
}
}
}
Has anyone seen this before? My one "Node" also has the label "Windows"
I didn't have the Pipeline plugin installd for some reason. It works now.
TL;DR:
I would like to use ActiveChoice parameters in a Multibranch Pipeline where choices are defined in a YAML file in the same repository as the pipeline.
Context:
I have config.yaml with the following contents:
CLUSTER:
dev: 'Cluster1'
test: 'Cluster2'
production: 'Cluster3'
And my Jenkinsfile looks like:
pipeline {
agent {
dockerfile {
args '-u root'
}
}
stages {
stage('Parameters') {
steps {
script {
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select the Environemnt from the Dropdown List',
filterLength: 1,
filterable: false,
name: 'Env',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: true,
script:
"return['Could not get The environemnts']"
],
script: [
classpath: [],
sandbox: true,
script:
'''
// Here I would like to read the keys from config.yaml
return list
'''
]
]
]
])
])
}
}
}
stage("Loading pre-defined configs") {
steps{
script{
conf = readYaml file: "config.yaml";
}
}
}
stage("Gather Config Parameter") {
options {
timeout(time: 1, unit: 'HOURS')
}
input {
message "Please submit config parameter"
parameters {
choice(name: 'ENV', choices: ['dev', 'test', 'production'])
}
}
steps{
// Validation of input params goes here
script {
env.CLUSTER = conf.CLUSTER[ENV]
}
}
}
}
}
I added the last 2 stages just to show what I currently have working, but it's a bit ugly as a solution:
The job has to be built without parameters, so I don't have an easy track of the values I used for each job.
I can't just built it with parameters and just leave, I have to wait for the agent to start the job, reach the stage, and then it will finally ask for input.
Choices are hardcoded.
The issue I'm currently facing is that config.yaml doesn't exist in the 'Parameters' stage since (as I understand) the repository hasn't been cloned yet. I also tried using
def yamlFile = readTrusted("config.yaml")
within the groovy code but it didn't work either.
I think one solution could be to try to do a cURL to the file, but I would need Git credentials and I'm not sure that I'm going to have them at that stage.
Do you have any other ideas on how I could handle this situation?
Is there a way to use Jenkins WORKSPACE environment variable in Jenkins declarative pipeline parameters?
Below attempt failed.
pipeline {
parameters {
extendedChoice description: 'Template in project',
multiSelectDelimiter: ',', name: 'TEMPLATE',
propertyFile: env.WORKSPACE + '/templates.properties',
quoteValue: false, saveJSONParameterToFile: false, type: 'PT_MULTI_LEVEL_SINGLE_SELECT',
value: 'Project,Template', visibleItemCount: 6
...
}
stages {
...
}
propertyFile: '${WORKSPACE}/templates.properties' didn't work either.
The environment variable can be accessed in various place in Jenkinsfile like:
def workspace
node {
workspace = env.WORKSPACE
}
pipeline {
agent any;
parameters {
string(name: 'JENKINS_WORKSPACE', defaultValue: workspace, description: 'Jenkins WORKSPACE')
}
stages {
stage('access env variable') {
steps {
// in groovy
echo "${env.WORKSPACE}"
//in shell
sh 'echo $WORKSPACE'
// in groovy script
script {
print env.WORKSPACE
}
}
}
}
}
The only way that worked is putting absolute path to Jenkins master workspace where properties file is located.
pipeline {
parameters {
extendedChoice description: 'Template in project',
multiSelectDelimiter: ',', name: 'TEMPLATE',
propertyFile: 'absolute_path_to_master_workspace/templates.properties',
quoteValue: false, saveJSONParameterToFile: false, type: 'PT_MULTI_LEVEL_SINGLE_SELECT',
value: 'Project,Template', visibleItemCount: 6
...
}
stages {
...
}
It seems that environment variables are not available during pipeline parameters definition before the pipeline actually triggered.
I have two JenkinsFile files where I want to share the same stages:
CommonJenkinsFile:
pipeline {
agent {
node {
label 'devel-slave'
}
}
stages {
stage("Select branch") {
options {
timeout(time: 3, unit: 'MINUTES')
}
steps {
script {
env.branchName = input(
id: 'userInput', message: 'Enter the name of the branch you want to deploy',
parameters: [
string(
defaultValue: '',
name: 'BranchName',
description: 'Name of the branch'),
]).replaceAll('\\/', '%2F')
}
}
}
}
Where I want to use it:
pipeline {
agent {
node {
label 'devel-slave'
}
}
load 'CommonJenkinsFile'
stages {
stage('Deploy to test') {
}
}
How can this stages be shared? Should I change to the Scripted Pipelines? Can they share stages or only steps?
CommonJenkinsfile cannot contain the pipeline directive (otherwise you are executing a pipeline within a pipeline). I think you also need to move it to the scripted syntax instead of the declarative (might be wrong there)
This file could look like this:
def commonStep(){
node('devel-slave'){
stage("Select branch") {
timeout(time: 3, unit: 'MINUTES'){
env.branchName = input ...
}
}
}
}
return this
You can then load it like this
stage('common step'){
script{
def sharedSteps = load "$workspace/common.groovy"
sharedSteps.commonStep()
}
}
I want to see the names of all failed tests in email body when an email is triggered by jenkins using editable email notification plugin.
I am using TestNg with selenium+java.
You can add allure reports in your tests and send the allure links or file via emial as in code below:
stage('Create properties file for allure') {
steps {
sh '''
export CHATBOT_ENV
touch allure-results/environment.properties
'''
}
}
stage('Allure reports') {
steps {
script {
allure([
includeProperties: true,
jdk: '',
properties: [],
reportBuildPolicy: 'ALWAYS',
results: [[path: 'allure-results/']]
])
}
}
}
}
post
{
always
{
echo 'This will always run'
emailext body: "Build URL: ${BUILD_URL}",
attachmentsPattern: "**/path_to_your_report",
subject: "$currentBuild.currentResult-$JOB_NAME",
to: 'nobody#optum.com'
}
}
}
THe build URL can be used to navigate to allure report.