我正在尝试使用以下代码检查工件中是否不存在Jenkins插件文件
但是,configurations.testPlugins会抛出异常并在可以从工件中获取某些文件后退出。
是否可以捕获异常并使其运行直到所有文件都经过验证?
testPlugins上是否有任何文档/示例?
谢谢!
task resolveTestPlugins(type: Copy) {
from configurations.testPlugins
into new File(sourceSets.test.output.resourcesDir, 'test-dependencies')
include '*.hpi'
include '*.jpi'
def mapping = [:]
doFirst {
configurations.testPlugins.resolvedConfiguration.resolvedArtifacts.each {
mapping[it.file.name] = "${it.name}.${it.extension}"
}
}
rename { mapping[it] }
doLast {
List<String> baseNames = source*.name.collect { mapping[it] }.collect { it[0..it.lastIndexOf('.') - 1] }
new File(destinationDir, 'index').setText(baseNames.join('\n'), 'UTF-8')
}
}
以下是更新的代码(用于调试目的),其中包含尝试捕获和错误。
task resolveTestPlugins(type: Copy) {
configurations.each { println it.name }
println configurations.testPlugins
try {
// Line 88
configurations.testPlugins.each {
println it.name
}
} catch(Exception e) {
println "Failed : " + e
}
try {
from configurations.testPlugins
into new File(sourceSets.test.output.resourcesDir, 'test-dependencies')
include '*.hpi'
include '*.jpi'
} catch(Exception e) {
println "Failed : " + e
}
def mapping = [:]
def pluginname = ""
doFirst {
try {
println "A-------- : " + pluginname
configurations.testPlugins.each {
try {
println "B-------- : " + pluginname
it.resolvedConfiguration.each {
try {
println "C-------- : " + pluginname
it.resolvedArtifacts.each{
pluginname = "${it.name}.${it.extension}"
println "D-------- : " + pluginname
executeBuildCommand(commandString, component)
mapping[it.file.name] = "${it.name}.${it.extension}"
}
} catch(Exception e) {
println "Failed : " + pluginname
}
}
} catch(Exception e) {
println "Failed : " + e
}
}
} catch(Exception e) {
println "Failed : " + e
}
/*
try {
configurations.testPlugins.resolvedConfiguration.resolvedArtifacts.each {
pluginname = "${it.name}.${it.extension}"
println "-------- : " + pluginname
executeBuildCommand(commandString, component)
mapping[it.file.name] = "${it.name}.${it.extension}"
}
} catch(Exception e) {
println "Failed : " + pluginname
}
*/
}
rename { mapping[it] }
doLast {
try {
List<String> baseNames = source*.name.collect { mapping[it] }.collect { it[0..it.lastIndexOf('.') - 1] }
new File(destinationDir, 'index').setText(baseNames.join('\n'), 'UTF-8')
} catch(ResolveException e) {
println "Failed : " + e
} catch(Exception e) {
println "Failed : " + e
}
}
}
以下是例外。一旦出现异常,构建将停止。在检查完所有插件之前,不确定是否可以继续运行。 谢谢!
Failed : org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':testPlugins'.
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\...\...\build.gradle' line: 88
* What went wrong:
Could not determine the dependencies of task ':resolveTestPlugins'.
> Could not resolve all dependencies for configuration ':testPlugins'.
> Could not determine artifacts for org.jenkins-ci.plugins:git-server:1.5
> Could not get resource 'https://.../artifactory/libs-release/org/jenkins-ci/plugins/git-server/1.5/git-server-1.5.hpi'.
> Could not HEAD 'https://.../artifactory/libs-release/org/jenkins-ci/plugins/git-server/1.5/git-server-1.5.hpi'. Received status code 401 from server: Unauthorized