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
Related
agent { label 'jenkins-slave' }
environment {
CRED_REPO_URL = 'gitcredentials.git'
SERVICES_REPO_URL = 'gitrepo'
ENV_NAME = 'dev_dev'
REGION = 'ap-south-1'
}
parameters {
choice name: 'ENV', choices: ['dev', 'qa'], description: 'Choose an env'
choice name: 'DIRS', choices: choiceArray, description: 'Choose a dir from branch'
gitParameter branchFilter: 'origin/(.*)',
tagFilter: '*',
defaultValue: 'main',
name: 'BRANCH',
type: 'BRANCHTAG',
quickFilterEnabled: 'true',
description: 'branch to execute',
useRepository: 'gitrepo'
}
}
facing some issue.so need to assist for this while select the branch in jenkins it has to shown that repo directories as a drop down.
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
when i run terraform with local variables inside variable.tf everything work like a charm
i want to pass Jenkins parameters inside terraform variable.tf file so it will be dynamic from Jenkins
how can i achieve it?
pipeline {
agent any
options {
skipDefaultCheckout true
}
environment {
TF_VAR_datacenter="${DATA_CENTER}"
TF_VAR_cluster="${CLUSTER}"
TF_VAR_esxi="${ESXI}"
TF_VAR_datastore="${DATASTORE}"
TF_VAR_network="${NETWORK}"
TF_VAR_server_hostname="${SERVER_HOSTNAME}"
TF_VAR_server_mac="${SERVER_MAC}"
}
parameters {
string(name: 'DATA_CENTER', defaultValue: 'xxx', description: 'vcenter data center',)
string(name: 'CLUSTER', defaultValue: 'xxx', description: 'data center cluster',)
string(name: 'ESXI', defaultValue: 'xxx', description: 'esxi hostname',)
string(name: 'DATASTORE', defaultValue: 'xxx', description: 'data center datastore',)
string(name: 'NETWORK', defaultValue: 'xxx', description: 'data center network',)
string(name: 'SERVER_HOSTNAME', defaultValue: 'xxx', description: 'server hostname',)
string(name: 'SERVER_MAC', defaultValue: 'xxx', description: 'server mac',)
string(name: 'SERVER_IP', defaultValue: 'xxx', description: 'server ip',)
string(name: 'SERVER_NETMASK', defaultValue: 'xxx', description: 'server netmask',)
string(name: 'SERVER_GATEWAY', defaultValue: 'xxx', description: 'server gateway',)
string(name: 'COBBLER_PROFILE', defaultValue: 'xxx', description: 'cobbler profile',)
choice(name: 'BUILD_DESTROY', description: '', choices: ['build' , 'destroy'])
}
stages {
stage('OS PROVISION') {
steps {
dir("/root/terraform"){
sh """
export TF_VAR_datacenter=${DATA_CENTER}
export TF_VAR_cluster=${CLUSTER}
export TF_VAR_esxi=${ESXI}
export TF_VAR_datastore=${DATASTORE}
export TF_VAR_network=${NETWORK}
export TF_VAR_server_hostname=${SERVER_HOSTNAME}
export TF_VAR_server_mac=${SERVER_MAC}
terraform init
terraform apply -auto-approve
"""
}
}
}
}
post {
always {
echo 'This will always run'
}
}
}
I prefer use this format:
terraform apply \
-var 'vpc_id=$(AWS_VPC_ID)' \
-var 'subnet_id=$(AWS_SUBNET_ID)' \
-var 'aws_region=$(AWS_REGION)' \
-var 'ami_id=$(AMI_ID)'\
-var 'instance_type=$(AWS_EC2_TYPE)' \
-var 'key_pair=$(KEY_PAIR_NAME)' \
-var 'tags={ "Owner":"$(OWNER)", "Service":"$(SERVICE)", "Terraform":"true", "Env":"$(ENV)" }'
Your question needs a bit more clarity, but I am going to make a few educated guesses.
with local variables inside variable.tf
Do you mean locals {, or what exactly do you mean by local variables?
pass Jenkins parameters inside terraform variable.tf file
This isn't the right file to 'pass parameters'. *.tf files are for declaring variables.
You are probably looking at *.tfvars files.
You have 3 options with *.tfvars files:
a file named exactly terraform.tfvars
a file named <anything>.auto.tfvars
a file named <anything>.tfvars which you reference using the -var-file CLI parameter.
The format of *.tfvars files is simply:
var1_name = var1_value
You can (must) use the usual HCL markup fo trings, lists, maps, ...
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.
I am trying to fetch the repo details from a variable in the jenkinsfile. Can someone guide on why this is not working?
parameters {
string(defaultValue: "develop", description: 'enter the branch name to use', name: 'branch')
string(defaultValue: "repo1", description: 'enter the repo name to use', name: 'reponame')
}
stage('Branch Update'){
dir("${param.reponame}"){
bat """ echo branch is ${params.branch}"""
}
}
When i run the above, I get the following error message:
groovy.lang.MissingPropertyException: No such property: param for class: groovy.lang.Binding
[Pipeline] }
You have a typo. Instead of param.reponame it should be params.reponame.