在詹金斯版中。 2.121.3使用管道尝试删除文件。其给脚本不允许的错误消息。
是否还有其他方法可以不使用OS命令删除Jenkins中的文件?
Scripts not permitted to use method java.io.File delete. Administrators can decide whether to approve or reject this signature.
[Pipeline] End of Pipeline
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method java.io.File delete
管道代码
stage('Delete test.zip file') {
if (fileExists('test.zip')) {
new File('test.zip').delete()
} else {
println "test.zip file not found"
}
}
答案 0 :(得分:1)
有几种替代方法:
#!/usr/bin/groovy
package org.utils
class PipelineUtils {
static def deleteFile(String name) { new File(name).delete() }
}
在管道脚本中,您需要导入库:
@Library('your-jenkins-library')_
import static org.utils.PipelineUtils.*
deleteFile('test.zip')
fileOperations([script.fileDeleteOperation(excludes: '', includes: 'test.zip')])
def new_exclude_patterns = [[pattern: ".git/**", type: 'EXCLUDE']]
cleanWs deleteDirs: false, skipWhenFailed: false, patterns: new_exclude_patterns
答案 1 :(得分:0)
导航到/ scriptApproval /(管理Jenkins>进程内脚本批准)并批准脚本。
答案 2 :(得分:0)
如果您正在linux从属服务器(或路径中带有sh的Windows从属服务器)上运行管道,则可以使用以下调用来避免任何脚本批准
c = Client()
r = c.lookup("213.73.91.35")
print(r.asn)