I have the following pipeline:
environment {
OUTPUT_FILE = 'OutputFile.zip'
}
stages {
stage('Build') {
steps {
// Build my app
zip archive: true, dir: 'zip', glob: '', zipFile: '${env.OUTPUT_FILE}'
}
}
}
I want to use the OUTPUT_FILE environment variable on the zip task, but it seems like the value is not resolved properly.
I have tried:
zip archive: true, dir: 'zip', glob: '', zipFile: '${OUTPUT_FILE}'
zip archive: true, dir: 'zip', glob: '', zipFile: '${env.OUTPUT_FILE}'
zip archive: true, dir: 'zip', glob: '', zipFile: '$OUTPUT_FILE'
None of them work.
You use incorrect syntax - in all your examples you use plain (and exact) string. However, in this case, you don't need to put env.OUTPUT_FILE inside any quotes, so the correct syntax is just:
zip archive: true, dir: 'zip', glob: '', zipFile: env.OUTPUT_FILE
or even
zip archive: true, dir: 'zip', glob: '', zipFile: OUTPUT_FILE
One thing worth mentioning. If you ever find yourself in a situation where you need to create a string using interpolation, then use double quotes. For instance, if you would like to echo the ZIP file name to console with some additional comment, then the following syntax would do the trick:
echo "The name of ZIP file is ${env.OUTPUT_FILE}"
Single quotes in Groovy are Java's String equivalent and they don't support variable interpolation.
Related
I want to do something very simple, in a folder I have a jar file and a folder called scripts that contains scripts. But I can get jenkins zip to do this.
zip dir: 'awsdeploy', exclude: '', glob: '', 'scripts/', zipFile: 'SQSToElasticProcessor.zip'
Arguments to "zip" must be explicitly named. # line 31, column 16.
zip dir: 'awsdeploy', exclude: '', glob: '*', 'scripts/*.*', zipFile: 'SQSToElasticProcessor.zip'
What I am trying to do is zip the following in the folder awsdeploy:
jarFile
scripts:
script1
script2
So I need to zip up the jar file and the subdirectory scripts
GENERATES REPORT FILE into /tmp (outside Jenkins Workspace)
def publisher = LastChanges.getLastChangesPublisher null, "SIDE", "LINE", true, true, "", "", "", "", ""
publisher.publishLastChanges()
def htmlDiff = publisher.getHtmlDiff()
writeFile file: "/tmp/${APPNAME}-${ENVIRONMENT}-build.diff.html", text: htmlDiff
ATTACHEMENT ANT BLOB
attachmentsPattern: "/tmp/*${APPNAME}-${ENVIRONMENT}-build.diff.html",
ERROR
ERROR: Error accessing files to attach: Expecting Ant GLOB pattern, but saw '/tmp/*/tmp/aaa-development-build.diff.html'. See http://ant.apache.org/manual/Types/fileset.html for syntax
Solved by using dir
dir ("tmp"){
attachmentsPattern: "**/*${APPNAME}-${ENVIRONMENT}-build.diff.html",
}
I'm working on implementing Checkmarx scans in our code repository. I'm using Jenkins and the CheckMarx plugin to accomplish this task. There are some folders I want to exclude from the scan; referencing the Jenkins plugin documentation it seems like all I have to do is add the folder names in the 'excludeFolders' field. However that doesn't appear to work, or maybe I don't have the value entered correctly.
I've tried '/test', 'test/', '!/test//*' but none work and the folder is still registered and zipped before it is uploaded to our CheckMarx server.
Below is what I have in my pipeline:
stage("Running CheckMarks for Layer"){
steps{
script{
def layer_dir = readFile file: 'layer-list'
def layer_list = layer_dir.split('\\r?\\n')
println (layer_list)
layer_list.each { layer ->
print (layer)
dir("${env.WORKSPACE}/layers/layer-name/$layer"){
step([
$class: 'CxScanBuilder',
comment: 'Layer scanning',
credentialsId: 'XXXX',
excludeFolders: 'test',
exclusionsSetting: 'global',
failBuildOnNewResults: false,
failBuildOnNewSeverity: 'MEDIUM',
filterPattern: '''!**/_cvs/**/*, !Checkmarx/Reports/*.*''',
fullScanCycle: 10,
incremental: true,
fullScansScheduled: true,
generatePdfReport: true,
preset: '36',
teamPath: "\\path\\to\\codebase",
projectName: "$layer",
sastEnabled: true,
sourceEncoding: '1',
vulnerabilityThresholdResult: 'FAILURE',
waitForResultsEnabled: true
])
}
}
}
}
}
Any suggestions on how to exclude the 'test' folder?
You should change your exclusionsSetting to 'job' instead of 'global', we can't override the global configurations.
Then you can add more filters in the filterPattern.
the filtering is really flakey - did you have any luck????
try add it to the filterPattern as !Test/*.* as well and play around with that...
Modify like below to exclude both target and test folders.
excludeFolders: 'target, test'
Jenkins console log:
[Cx-Debug]: Excluded Dir: src/test
[Cx-Debug]: Excluded Dir: target
If you are running on Windows you need to use the following pattern: !**\\test\\**\\*
On Linux: !**/test/**/*
I have a Jenkinsfile that deploys my angular app code to a site using the Publish over FTP plugin. All of the files in the dist folder are transferred except an assets subfolder. I have tried putting in the following values for the sourceFiles parameter with no success: 'webapp/dist/', 'webapp/dist/**', 'webapp/dist/**/*'.
Here is the publish over FTP part of my Jenkinsfile:
stage('Deploy') {
steps {
echo 'Deploying....'
ftpPublisher paramPublish: null, masterNodeName:'', alwaysPublishFromMaster: true, continueOnError: false, failOnError: true, publishers: [
[configName: 'Angular app', verbose: true, transfers: [
[asciiMode: false, cleanRemote: true, makeEmptyDirs:true, excludes: '', flatten: false,
noDefaultExcludes: false, patternSeparator: '[, ]+',
remoteDirectory: "webapp",
removePrefix: "webapp/dist",
remoteDirectorySDF: false,
sourceFiles: 'webapp/dist/**/*']
], usePromotionTimestamp: false, `enter code here`useWorkspaceInPromotion: false]
]
}
}
I've looked at the Publish over FTP pipeline documentation: https://jenkins.io/doc/pipeline/steps/publish-over-ftp/ and couldn't find anything parameters that I was missing. I'm stuck.
I was able to solve the issue. I changed the title of the pipeline to all lowercase letters without any spaces. I then changed the file path of the workspace folder to 'C:/jenkinsworkspace/${ITEM_FULL_NAME}' by modifying the workspaceDir entry in the config.xml located in the Jenkins root directory. I stopped the Jenkins service before modifying the config.xml. Both the assets folder and the favicon got generated in the build. It was one of the solutions mentioned in https://github.com/angular/angular-cli/issues/9230. Thanks for your help #Alberto L. Bonfiglio.
I was trying to copy all the files within a directory from windows to unix within groovy method using following. But it does give an error saying No such file or directory
def antMove = new AntBuilder()
antMove.scp(trust: 'true',
file: "D:\\MyFolder\\input\\*",
todir: "username#[IP]:/tmp/rw_input/",
port: "22",
keyfile: Key,
passphrase: Passphrase,
verbose: "true")
I tried different option as well like *.* and * . But no luck
If I give just one file name here like test.txt its working fine
Thanks
Fileset can be added in the following way:
def ant = new AntBuilder()
ant.scp(
todir: "username#[IP]:/tmp/rw_input/",
verbose: true,
keyfile: "key",
trust: true
) {
fileset(dir: "D:\\MyFolder\\input\\") {
include(name: '*')
}
}