分享一段新手也能看懂的jenkins上传文件到阿里云oss脚本,便于其他同学快速入门.
步骤
下面实现了代码从仓库到上传文件到阿里云oss过程,分别是
- 拉取仓库代码
- 打包代码
- 上传
- 清理当前工作空间
源码
pipeline {
agent any
parameters{
string(name:'git_url',defaultValue:'https:/xxxx.cn/xzz/xxxxx.git',description:'仓库地址')
string(name:'version',defaultValue:'main',description:'版本')
string(name:'build_name',defaultValue:'xxxxxx',description:'打包名称')
}
stages {
stage('拉取') {
steps {
deleteDir()
checkout([
$class: 'GitSCM',
branches: [[name: '$version']],
userRemoteConfigs: [[
url: '$git_url'
]],
extensions: [[$class: 'CloneOption', depth: 1, noTags: false, reference: '', shallow: true]]
])
}
}
stage('打包') {
steps {
sh 'tar -zcvf "$build_name".tar.gz *'
}
}
stage("上传"){
steps{
aliyunOSSUpload accessKeyId: 'xxxxxxx',accessKeySecret: 'xxxxxxx', bucketName: 'project', endpoint: 'oss-cn-hangzhou.aliyuncs.com', localPath: "/project.tar.gz", maxRetries:"3", remotePath: '/demo/project.tar.gz'
}
}
stage('清理工作空间'){
steps{
deleteDir()
}
}
}
}