-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Different error handling needed when Job is triggered by user or by Timer if no file is provided #54
Comments
Will have to look into it when I get a chance. Did you try the |
Yes, the behaviour is also inconsistent when using
nevertheless, your hint to pipeline {
agent any
parameters {
stashedFile(name: 'ZIP_FILE', description: "File to unzip")
}
triggers {
cron('* * * * *')
}
stages {
stage('test')
{
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
//Fine when triggered manually without a file, fails when TimerTriggered without a file (because ZIP_FILE variable is not set)
withFileParameter(name:'ZIP_FILE', allowNoFile: true) { sh 'echo doing stuff with $ZIP_FILE' }
}
catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
//Fine when triggered manually without a file, fails when TimerTriggered without a file (because withFileParameter throws an error)
withFileParameter(name:'ZIP_FILE') { sh 'echo doing stuff with $ZIP_FILE' }
}
}
}
//my intended use
stage('check file existence')
{
environment {
DIR = "Bin"
}
when {
expression {
withFileParameter(name:'ZIP_FILE', allowNoFile: true) {
//two checks needed: variable has to be set and filesisze may not be zero
sh(returnStatus:true, script: '[ ! -z "$ZIP_FILE" ] && [ -s $ZIP_FILE ]' ) == 0 }
}
}
stages {
stage('unpack file') {
steps {
withFileParameter(name:'ZIP_FILE') {
unzip zipFile: ZIP_FILE, dir: DIR
}
}
}
}
}
}
} |
note: I'm still testing with file-parameters:99.102.vbc6a133bcbbb |
I'd like to add to this issue, since it is quite similar. Automatic triggers that don't supply any file can fail when trying to access the parameter by name, through the global
If accessed like this (similar to how you can access other parameters):
will fail with an error Edit: It seems it is the One quick solution is to allow a "default" value? Probably supplied with a base64 string (allowing empty would be nice). In our case, we have a job that's triggered automatically by another job, but if triggered manually, the user can supply the OPTIONAL file to update the current environment. If you want to ask why we are accessing it through |
Related to #26. |
Also related to #22: you will get a |
Allow both kinds of file parameters to specify a default value (empty or some Base64 content) seems like a reasonable improvement that would obviate the need for error handling under the assumption that
There are several different ways to pass file parameters (at least GUI upload, HTTP POST, CLI, |
I found a solution for this issue: we can check reliably for the *_FILENAME-variable. I'm fine with that. pipeline {
agent any
parameters {
stashedFile 'ZIPFILE'
}
triggers {
cron('0 * * * *')
}
stages {
stage('file handling')
{
environment {
DIR = "Bin"
}
when {
expression { env.ZIPFILE_FILENAME }
}
stages {
stage('unpack file') {
steps {
withFileParameter('ZIPFILE') {
unzip zipFile: 'ZIPFILE', dir: "$DIR"
}
}
}
}
}
}
} |
That seems like a workaround, not a solution. |
Version report
Jenkins and plugins versions report:
Reproduction steps
Results
Expected result:
I'd expect to do the same error handling, no matter whether the pipeline was started manually or by another trigger
Actual result:
unstashing fails when the pipeline is TimerTriggered or by SCM
unstashing works and the file exists with a size of 0 when triggering the pipeline manually
The text was updated successfully, but these errors were encountered: