代码拉取完成,页面将自动刷新
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
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。