I am trying to use file parameter which is not saving the file in the workspace for pipeline project its returning the filename that was uploaded (not the full path only the filename)
pipeline {
agent any
parameters {
file(name:'FILE', description: 'upload excel file')
}
stages {
stage('upload') {
steps {
script {
echo "Parameter file: ${params}" // output: Parameter file: [:]
echo "file name: ${FILE}" // file name: uploaded_file.xlsx
def workspace = pwd()
def fullPath = workspace + "\\" + FILE
if (fileExists(fullPath)) {
echo "File exists"
} else {
echo "File does not exist" // this will be run as fullPath has no such file.
}
}
}
}
}
}
Just to let you know params.FILE
is null and FILE
contains the filename.
Now if I try to use readFile(FILE)
its working and returning the content of the file (without full path as FILE is just the filename).
So, its there a good solution to save the file in the workspace.
I know we can use file parameter plugin but try to do it using file parameter (if possible).
And any explanation how readFile
is working?