主动选择参数字符串验证詹金斯管道

时间:2020-10-01 04:35:02

标签: validation jenkins groovy

我正在尝试对管道中的活动选择参数进行验证检查,如果参数为空,则管道将通过声明消息而失败 例如“输入参数不能为空”。

从活动选择参数中过滤工件

Filter the artifact from Active choice parameter

如果没有工件,那么这里的结果当然不会是预期的

If artifact is not available, of-course result would be none here which is expected

Job仍然使用空参数,如果字符串为空,我想在此处进行检查以使此作业失败

Job still goes through with empty parameter, I want to put check here to make this job fail if string is blank

这是用于从注册表中检索参数列表的常规脚本:

bitCounter.cpp:15:14: error: no matching function for call to 'converter'
  string c = converter(argv[2], argv[3], argv[4]);
             ^~~~~~~~~
bitCounter.cpp:8:8: note: candidate function not viable: no known conversion from 'char *' to 'int' for 2nd argument; dereference the argument with *
string converter(string num, int base1, int base2);

我可以使用类似于def call(body) { properties([ disableConcurrentBuilds(), buildDiscarder( logRotator( artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '15')), parameters([ [$class: 'ChoiceParameter', choiceType: 'PT_SINGLE_SELECT', description: '', filterLength: 1, filterable: true, name: 'RC_artifact', script: [ $class: 'GroovyScript', fallbackScript: [ classpath: [], sandbox: true, script: ''], script: [ classpath: [], sandbox: true, script: '''import groovy.json.JsonSlurper def docker_image_tags_url = "https://xxxx.azurecr.io/v2/cmp/rc/xxxx/tags/list" try { def http_client = new URL(docker_image_tags_url).openConnection() as HttpURLConnection def authString = "********************************" http_client.setRequestProperty("Authorization", "Basic ${authString}") http_client.setRequestMethod(\'GET\') http_client.connect() def acr_response = [:] if (http_client.responseCode == 200) { acr_response = new JsonSlurper().parseText(http_client.inputStream.getText(\'UTF-8\')) } else { println("HTTP response error") System.exit(0) } return acr_response.tags.sort() } catch (Exception e) { println(e) }''' ] ] ] ]) ]) 插件的东西来实现它吗?

0 个答案:

没有答案