3 Star 1 Fork 0

toliong/jenkins_pipeline

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Jenkinsfile 2.82 KB
一键复制 编辑 原始数据 按行查看 历史
pipeline{
agent any //any,none,label,node
options {
timeout(time: 1, unit: 'HOURS')
timestamps()
}
environment {
CREDENTIALS_ID = 'fc0c712d-8049-4d3b-91b9-2c8a54788db8'
REPO_URL = 'https://codeup.aliyun.com/6062898b6cc98419b95d4a7e/devops/jenkinslib.git'
BUILD_COMMAND ='mvn -B clean package -P dev -Dmaven.test.skip=true -U'
}
tools {
// 获取通过自动安装或手动放置工具的环境变量。支持maven/jdk/gradle。工具的名称必须在系统设置->全局工具配置中定义。
maven 'M3'
jdk "java11"
}
parameters {
string(name: 'DEPLOY_ENV', defaultValue: 'staging', description: '')
// https://groups.google.com/g/jenkinsci-users/c/EdAyCvnkWxA
// useRepository:如果在任务中定义了多个存储库,则此选项指定在获取数据时考虑哪个存储库。如果未定义该选项,则取第一个定义的存储库。该选项是一个正则表达式,与“Repository URL”相比较。
gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'BRANCH_NAME', type: 'PT_BRANCH', quickFilterEnabled: true, useRepository: "[^devops]"
}
stages{
stage("Checkout") {
steps{
// git branch: ${BRANCH_NAME}, credentialsId: ${CREDENTIALS_ID}, url: ${REPO_URL}
checkout([$class: 'GitSCM', branches: [[name: "${params.BRANCH_NAME}"]], extensions: [], userRemoteConfigs: [[credentialsId: "${CREDENTIALS_ID}", url: "${REPO_URL}"]]])
}
}
stage("Package") {
steps {
script {
sh "${BUILD_COMMAND}"
}
}
}
stage('writefile_and_stash'){
steps {
script {
// "amVua2lucyBib29r" 是"jenkins book"进行Base64编码后的值
writeFile(file: "base64File", text: "amVua2lucyBib29r", encoding: "Base64")
def content = readFile(file: "base64File", encoding: "UTF-8")
// 文件保存
stash(name: "abc", include: "a.txt")
echo "${content}"
// 打印结果: jenkins book
}
}
}
stage("unstash") {
steps {
script {
// 取出stash的文件
unstash("abc")
def content = readFile("base64File")
echo "unstash file content: ${content}"
}
}
}
}
post {
always{
echo "总是会执行"
archiveArtifacts artifacts: 'base64File', fingerprint: true
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/toliong/jenkins_pipeline.git
git@gitee.com:toliong/jenkins_pipeline.git
toliong
jenkins_pipeline
jenkins_pipeline
master

搜索帮助