I have installed the following plugin in Jenkins environmentDashboard(https://plugins.jenkins.io/environment-dashboard/)
Need to incorporate the feature in Jenkinsfile, Sample Jenkinsfile
pipeline {
agent any
parameters {
string(name: "branch_name", defaultValue: "master", description: "Enter the branch name")
string(name: "project_name", defaultValue: "TestAutomation" , description:"BuildWorkspace")
choice(name: "mach_name", choices: ["LINUX" , "WINDOWS"], description: "OS Selection")
string(name: "build_suffix", defaultValue:"", description: "Provide a build suffix name")
}
environment{
TARBALL_PATH = ""
}
Wrappers{
environmentDashboard {
environmentName('Testing')
componentName('GCC_COMPILER')
buildNumber({BUILD_ID})
buildJob({JOB_NAME})
packageName('TARBALL')
addColumns(true)
columns('RESULT', 'PASS')
}
}
stages {
stage('TARBALL GENERATION') {
steps {
script{
buildName "${mach_name}#${BUILD_NUMBER}"
buildDescription "${mach_name} Test Execution on ${NODE_NAME}"
}
echo "Branch name is ${params.branch_name}"
echo "Preferred MACH: ${params.mach_name}"
echo "Reached Here after printing selected parameters"
sh """
#!/bin/bash
echo "Multiline shell steps execution"
printenv | sort
"""
} //steps
} //stage
}//Stages
}//pipeline
Getting the error as follows:
Running in Durability level: MAX_SURVIVABILITY
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 13: Undefined section "Wrappers" # line 13, column 5.
Wrappers{
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:561)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:522)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:327)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:427)
Finished: FAILURE
You need to write wrappers in lowercase.
Like wrappers{}
Not Wrappers{}
For pipeline job you need to use the following code:
environmentDashboard(addColumns: false, buildJob: '', buildNumber: 'Version-1', componentName: 'WebApp-1', data: [], nameOfEnv: 'Environment-1', packageName: '') {
// some block
}
In fact, you can skip // some block and just use {}. That worked for me.
Related
I am trying to add a function in JenkinsFile Declarative pipelines parameter's description but struggling to make it work.
Idea is to have a Jenkins Job specific for the environment. and would like to see the choice parameter to show environment name in the description of the variable.
My pipeline looks like this
def check_env = app_env(ENVS, env.JOB_NAME)
pipeline {
agent { label 'master' }
options {
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '20'))
timestamps()
}
parameters{
string(name: 'myVariable', defaultValue: "/", description: 'Enter Path To App e.g / OR /dummy_path for ' {check_env} )
}
stages{
stage('Running App') {
agent {
docker {
image 'myApp:latest'
}
}
steps{
script{
sh label: 'App', script: "echo "App is running in ${check_env} "
}
}
}
}
}
}
I have tried multiple combinations for check_env e.g check_env, check_env(), ${check_env} function but none of them worked.
String Interpolation
I believe this is simply a String Interpolation issue. Notice my use of double quotes below
parameters{
string(name: 'myVariable', defaultValue: "/", description: "Enter Path To App e.g / OR /dummy_path for ${check_env}")
}
Your build page should then interpolate your variable
To test I simply set def check_env = 'live' since I do not have the code for your method
I am having jenkin Jenkins 2.289.1, at I am converting the existing job to the pipeline.
The same batch which is working in job but is not working in pipeline.
Even when the batch file does not exist, no error thrown but task ended as completed.
Any idea on the issue?
pipeline {
agent any
parameters {
choice(name: 'RELEASE', choices: ['860', '859', '858','857'], description: 'Pick something')
string(name: 'SrcTestSetNameToCopy', defaultValue: '', description: 'Source ALM test Set Name')
string(name: 'TestSetNameToBeCreated', defaultValue: '', description: 'Test Set Name to create')
choice(name: 'Platform', choices: ['ORACLE', 'MICROSFT', 'DB2ODBC'], description: 'Pick something')
string(name: 'BuildOverride', defaultValue: '', description: '4 dit build overwrite value')
choice(name: 'EnvnBuildType', choices: ['DEP', 'QAE'], description: 'Pick something')
booleanParam(name: 'TOGGLE', defaultValue: true, description: 'Toggle this value')
}
stages {
stage('Create ALM Test Set') {
steps {
// bat "\"C:\\JenKin_Jobs\\Test.bat\""
// bat 'C:/JenKin_Jobs/Test1.bat'
// bat 'wmic computersystem get name'
//bat 'echo %PATH%'
echo 'selva'
echo "Current workspace is $WORKSPACE"
//bat returnStatus: true, script: 'C:\\JenKin_Jobs\\Test.bat'
bat script: 'C:\\JenKin_Jobs\\Test.bat'
}
}
}
}
pipeline {
agent any
stages {
stage('Hello') {
steps {
// below simple echo executed
echo 'Hello World'
//bat 'C:\\JenKin_Jobs\\NetUSeIDrive.bat'
bat 'cmd.exe "/c C:\\JenKin_Jobs\\NetUSeIDrive.bat" '
bat 'cmd.exe /c c:\\JenKin_Jobs\\SQAClnUp.bat "I:\\\\***\\\\SQA_CONFIG_FILES\\\\859 Stuff\\\\####\\\\P05\\\\P05B"'
}
}
}
}
The pipeline works in one set of box but not in another? IS there any config missing between the boxes. Both are usins same jenkin version
I stuck with for loop condition in Pipeline
pipeline {
agent any
stages{
stage ('Showing Working Space') {
when {
anyOf {
environment name: 'Test', value: 'ALL'
environment name: 'Test', value: 'IMAGE'
}
}
steps {
sh "echo Display ${Var1}"
script{
sh 'for service in (echo "$Var1"|sed "s/,/ /g");do echo $service; done'
}
}
}
}
}
Getting error like " syntax error near unexpected token `('"
Var1 = has multiple values
Need to execute the "For loop" to pass the values to another script
Please help on this
I believe what you want is
pipeline {
agent any
stages {
stage('Showing Working Space') {
when {
anyOf {
environment name: 'Test', value: 'ALL'
environment name: 'Test', value: 'IMAGE'
}
}
steps {
sh "echo Display ${Var1}"
script {
sh 'for service in $(echo "$Var1"|sed "s/,/ /g"); do echo $service; done'
}
}
}
}
}
In essence, replace service in (echo with service in $(echo (note the $).
I'm attempting to add a post-build step to my jenkinsfile to apply a label to a build. The Jenkins variables are resolved fine, but the environment variables I've defined globally within the file are not resolved. Here's the relevant bits:
pipeline {
environment {
VERSION_MAJOR = '1'
VERSION_MINOR = '0'
VERSION_PATCH = '0'
}
stages {
stage('Build') {
steps {
echo('Testing p4Tag')
}
}
}
post {
success {
build job: 'Copy-Installers',
parameters: [
//
string(name: 'MASTER_VERSION_MAJOR', value: '${VERSION_MAJOR}'),
string(name: 'MASTER_VERSION_MINOR', value: '${VERSION_MINOR}'),
string(name: 'MASTER_VERSION_FEATURE', value: '${VERSION_PATCH}'),
string(name: 'MASTER_BUILD_NUMBER', value: '${BUILD_NUMBER}'),
string(name: 'COMPONENT_NAME', value: 'Console')
}
}
}
The downstream build fails. Looking at the log it appears the local environment variables are not passed in:
The Build Number name is: ${VERSION_MAJOR}
The Build Number name is: ${VERSION_MINOR}
The Build Number name is: ${VERSION_PATCH}
The Build Number name is: 924
The Build environment name is: Console
Update
I've tried the following variations as well:
value: '${env.VERSION_MAJOR}' - Fails similarly to above
value: '$VERSION_MAJOR' - Fails similarly to above
value: $VERSION_MAJOR - Fails with "no such property" error
Update 2
For what it's worth, these variables can be referenced from the stage section. For instance, this works as expected:
stage('build') {
sh('./Build/build-package.sh $VERSION_MAJOR $VERSION_MINOR $VERSION_PATCH $BUILD_NUMBER')
}
My example:
pipeline {
agent any
parameters {
choice(
name: 'myParameter',
choices: "Option1\Option2",
description: 'interesting stuff' )
}
}
outputs with error:
" unexpected char: '\' " on the line with "choices" "
Following these instructions: https://github.com/jenkinsci/pipeline-model-definition-plugin/wiki/Parametrized-pipelines
Any idea or advice on what I do wrong?
The documentation for declarative jenkins pipelines says:
A choice parameter, for example:
pipeline {
.....
parameters {
choice(name: 'CHOICES', choices: ['one', 'two', 'three'], description: '') }
First one is the default value
You need to use \n instead of \.
See this code:
pipeline {
agent any
parameters {
choice(
name: 'myParameter',
choices: "Option1\nOption2",
description: 'interesting stuff' )
}
}
The arguably most elegant way to separate choices is by using an array like so:
pipeline {
agent any
parameters {
choice(
name: 'Env',
choices: ['DEV', 'QA', 'UAT', 'PROD'],
description: 'Passing the Environment'
)
}
stages {
stage('Environment') {
steps {
echo " The environment is ${params.Env}"
}
}
}
}