我有一个场景,我需要将大(mb)文件从 Jenkins GUI 上传到工作区?
有办法实现这个要求吗?
请让我知道可用的解决方案。
文件应上传到工作区。 预先感谢
要将大文件从 Jenkins GUI 上传到相应的构建工作区,您可以使用 Jenkins 中的“文件参数”功能。该功能允许用户通过 Jenkins GUI 上传文件,然后可以通过其工作区中的构建作业访问该文件。
┌────────────────┐ ┌─────────────┐ ┌────────────────────────────────┐
│ Jenkins Server │ ──> │ Jenkins GUI │ ──> │ File Upload via File Parameter │
└────────────────┘ └─────────────┘ └────────────────────────────────┘
│ │
V V
┌────────────────┐ ┌──────────────────────────────┐
│ Build Workspace│ ◄────────────────── │ File copied to workspace │
│ │ during build │ during build (using script) │
└────────────────┘ └──────────────────────────────┘
UPLOAD_FILE
)。在构建脚本(如 shell 脚本)中,通过参数名称引用上传的文件。对于管道作业,您可以直接在脚本中使用它。
# Shell Script Example
# Access the uploaded file using the parameter name
cp $UPLOAD_FILE ${WORKSPACE}/desired-subfolder/
// Pipeline Script Example
pipeline {
agent any
parameters {
file(name: 'UPLOAD_FILE')
}
stages {
stage('Upload File') {
steps {
script {
// Copy the file to the workspace
sh "cp \$UPLOAD_FILE \${WORKSPACE}/desired-subfolder/"
}
}
}
}
}
您可能想尝试“Jenkins 文件参数插件”
提供与 Pipeline 兼容的替代文件参数类型,并且不会受到 Jenkins 核心内置类型的架构缺陷的影响。
使用文件参数插件,您的 Jenkins 管道脚本在处理文件上传时看起来会略有不同:
对于 Base64 文件参数:
pipeline {
agent any
parameters {
base64File 'FILE'
}
stages {
stage('Upload File') {
steps {
withFileParameter('FILE') {
// Use the file here, for example, copying it to a desired location
sh 'cp $FILE ${WORKSPACE}/desired-subfolder/'
}
}
}
}
}
对于 stashed 文件参数:
pipeline {
agent any
parameters {
stashedFile 'FILE'
}
stages {
stage('Upload File') {
steps {
unstash 'FILE'
// Use the file here, for example, moving it to keep the original filename
sh 'mv FILE ${WORKSPACE}/desired-subfolder/$FILE_FILENAME'
}
}
}
}