jenkins-pipeline - JenkinsFile 默认工作区名称太长
问题描述
我目前正在使用 bitbucket 设置 jenkins。我已经创建了一个新的 jenkins 项目作为多分支项目。
JenkinsFile 托管在 git 存储库中。如何强制 jenkins 生成比默认分支名称更短的分支名称。
E:\jenkins\workspace\reposName-BrancheName-ZKIZ7BNGL6RTDKLQAQ7QR4FKZMOB3DDAVZ564BLWT2BY5ZV652VA
我怎样才能搭上ZKIZ7BNGL6RTDKLQAQ7QR4FKZMOB3DDAVZ564BLWT2BY5ZV652VA
这是我的詹金斯文件
#!/usr/bin/env groovy
env.PATH = env.PATH + ";c:\\Windows\\System32"
def call(String label = null, Closure body) {
node(label) {
String path = pwd()
String branchName = env.BRANCH_NAME
if (branchName) {
path = path.split(Pattern.quote(File.separator))
def workspaceRoot = path[0..<-1].join(File.separator)
def currentWs = path[-1]
String newWorkspace = env.JOB_NAME.replace('/', '-')
newWorkspace = newWorkspace.replace(File.separator, '-')
newWorkspace = newWorkspace.replace('%2f', '-')
newWorkspace = newWorkspace.replace('%2F', '-')
if (currentWs =~ '@') {
newWorkspace = "${newWorkspace}@${currentWs.split('@')[-1]}"
}
path = "${workspaceRoot}${File.separator}${newWorkspace}"
}
ws(path) {
body()
}
}
}
pipeline
{
} // pipeline
有没有办法强制詹金斯生成一个更短的名字?
解决方案
您可以jenkins.branch.WorkspaceLocatorImpl.PATH_MAX=20
在 jenkins 的脚本控制台中更改 的值。
如果您重新启动 jenkins 服务器,更改将丢失。要使更改永久生效,请添加此 java 属性-Djenkins.branch.WorkspaceLocatorImpl.PATH_MAX=20
推荐阅读
- python - 使用openpyxl将值复制到不同工作表中的特定列
- google-cloud-platform - Google Cloud Build 不缓存自定义构建步骤?
- android - 如何在 Android 中提取 PDFTron 中的注释并保存到数据库?
- kotlin - onPlaceSelected 内部的方法不执行
- spring - Spring Batch 中的数据库锁定
- python - 使用 QPainter 覆盖两个具有 alpha 值的像素图
- javascript - Electron + xmpp.js:如何调试 SSL 自签名错误消息?
- c# - JsonConvert.DeserializeObject
返回空列表 - java - 合并排序逻辑错误
- javascript - 为什么在内联函数中使用时出现“no-unused-var”错误