'How to convert freestyle jenkins to jenkins scripted pipeline
I am writing because for several weeks I have been struggling with rewriting the freestyle jenkins code that was executed in the / bin / bash shell on the pipeline. At the beginning, I was wondering what type of pipeline to choose, whether it is a declarative pipeline or a scripted pipeline. I chose the scripted pipeline because with this script I run gulp that the pipeline declarative would not have access to.
The first problem I encountered was the lack of a file in the $ {WORKSPACE}/artifacts directory for a given job, which I previously uploaded using the add file option:
this was not a problem in the freestyle pipeline.
Second problem, how should I write variables in the scripted pipeline is something like below correct ??
def artifacts_dir="\${WORKSPACE}/artifacts"
def artefact_dir= "\${WORKSPACE}/artifacts}"
def scfs_dir="\${WORKSPACE}/scf_migration_validator/scf_data/baseline/SBTS/"
def admin_trunk_dir="/home/jenkins/admin_repos/admin_trunk"
def cores=14
build_admin_html (dir, branch) {
sh """
#!/bin/bash
set +x
touch rules.pdl
echo Building admin HTML!
cd ${dir}/admin
cp ${artifacts_dir}/rules.pdl ${dir}/admin/admin-core/resources/pdlValidation/PDL/SRAN/
gulp package --skip-wasm --svn-branch=${branch} --max-old-space-size=8192 --use-local --no-auth
cp ${dir}/admin/.tmp/bundles/no-auth/ADMIN.html ${artifacts_dir}
echo
"""
}
timestamps {
node ('local-docker') {
stage ('Build_Knife - Checkout') {
checkout([$class: 'GitSCM', branches: [[name: '**']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'cab881bd-a4c4-41d8-aa9c-74a20d341903', url: '[email protected]:szmajdzi/pdl-testing.git']]])
}
stage ('Build_Knife - Build') {
build_admin_html (admin_trunk_dir, 'trunk')
}
}
}
I should write like this:
$ {artifacts_dir}
or so
\ $ {artifacts_dir}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

