使用OR关系进行JSR-303验证(JSR-303 validation using an OR relationship)
我在我的bean中有一个字段,我想要是Null,或者是过去的日期。 JSR-303为Null和Past提供注释,但如果我同时应用它,它将永远不会验证,因为它不能同时为Null和Past。 我想在OR关系中组合验证。 我很确定我必须为此创建自己的验证器实现,但我希望我遗漏了一些东西,你们中的一个可以告诉我如何在OR关系中轻松组合现有的验证器。
I have a field in my bean that I would like to be either Null, OR a date in the past. JSR-303 provides annotations for Null and Past, but if I apply both the it will never validate because it can't be both Null and Past. I would like to combine the validations in an OR relationship. I'm pretty sure I'll have to create my own validator implementation for that, but I'm hoping I'm missing something and one of you can show me how to easily combine the existing validators in an OR relationship.
原文:https://stackoverflow.com/questions/4188293
最满意答案
在参数块中定义您的参数:
pipeline { agent any parameters { string(defaultValue: 'us-west-2', description: 'Provide your region', name: 'REGION') } stages { stage('declarative'){ steps { print params.REGION sh "echo ${params.REGION}" } } stage('scripted'){ steps { script { print params.REGION } } } } }
输出:
[Pipeline] { [Pipeline] stage [Pipeline] { (declarative) [Pipeline] echo us-west-2 [Pipeline] sh [test] Running shell script + echo us-west-2 us-west-2 [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (scripted) [Pipeline] script [Pipeline] { [Pipeline] echo us-west-2 [Pipeline] } [Pipeline] // script [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS
Define your parameters in a parameter block:
pipeline { agent any parameters { string(defaultValue: 'us-west-2', description: 'Provide your region', name: 'REGION') } stages { stage('declarative'){ steps { print params.REGION sh "echo ${params.REGION}" } } stage('scripted'){ steps { script { print params.REGION } } } } }
Output:
[Pipeline] { [Pipeline] stage [Pipeline] { (declarative) [Pipeline] echo us-west-2 [Pipeline] sh [test] Running shell script + echo us-west-2 us-west-2 [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (scripted) [Pipeline] script [Pipeline] { [Pipeline] echo us-west-2 [Pipeline] } [Pipeline] // script [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS
相关问答
更多-
我可以在声明式Jenkins管道中定义多个代理标签吗?(Can I define multiple agent labels in a declarative Jenkins Pipeline?)[2022-05-04]
您可以在Jenkins安装中看到'Pipeline-syntax'帮助,并查看示例步骤“节点”参考。 你可以使用exprA||exprB : node('small||medium') { // some block } You can see the 'Pipeline-syntax' help within your Jenkins installation and see the sample step "node" reference. You can use exprA||exprB: ... -
如何在Jenkins的声明式管道中执行简单的if语句 你发布的第一个片段是一个很好的选择。 你可以在这个第二阶段使用'not'指令: stage('then') { when {
} steps { ... } } stage('else') { when { not { } } steps { ... } } 但是,这并不比将其包装在'脚本'声明中更好,因为你甚至可以保持两 ... -
在参数块中定义您的参数: pipeline { agent any parameters { string(defaultValue: 'us-west-2', description: 'Provide your region', name: 'REGION') } stages { stage('declarative'){ steps { print params.REGION ...
-
Jenkins声明式管道与来自SCM的Docker / Dockerfile代理(Jenkins declarative pipeline with Docker/Dockerfile agent from SCM)[2021-08-30]
您可以尝试为每个阶段单独声明代理,对于结帐阶段,您可以为其他人使用某个默认代理和泊坞窗代理。 pipeline { agent none stage ('Checkout') { agent any steps { git( url: 'https://www.github.com/...', credentialsId: 'CREDENTIALS', ... -
您需要在第一步结束时使用stash命令,然后在需要文件时unstash存储 我认为这些可以在代码片段生成器中找到 根据文件 保存一组文件以便稍后在同一个版本中使用,通常在另一个节点/工作区上。 存储的文件不可用,通常在构建结束时被丢弃。 请注意,存储和取消存储步骤旨在用于小文件。 对于大数据传输,请使用External Workspace Manager插件,或者使用外部存储库管理器,如Nexus或Artifactory You need to use the stash command at the en ...
-
在声明性Jenkins管道中获取最新的成功提交ID(Get the latest successful commit ID in a declarative Jenkins pipeline)[2022-05-20]
截至管道的最新更新(更新截至09-22-2017,Jenkins版本2.78),防止git模块环境变量暴露的错误已得到修复,这使得这不再是一个问题。 As of the latest updates to the pipeline (updates as of 09-22-2017, Jenkins version 2.78), the bug preventing the git modules environment variables being exposed has been fixed maki ... -
您可以迭代所有现有的hudson.model.Job实例并获取它们的名称。 以下应该工作 @NonCPS def getJenkinsJobs() { Jenkins.instance.getAllItems(hudson.model.Job)*.fullName.join('\n') } pipeline { agent any parameters { choice(choices: getJenkinsJobs(), name: 'JOB') } ...
-
如何在Jenkins声明式管道中发送“恢复正常”通知?(How to send “back to normal” notifications in Jenkins Declarative Pipeline?)[2022-04-30]
问题在于,在声明的post部分中,currentBuild.result未设置为SUCCESS。 尽管已经设置了FAILURE和ABORTED。 所以这里的行为似乎目前不一致。 我已经改进了我的答案, 如何为Jenkins管道获得相同的Mailer行为来更好地处理这种情况: pipeline { agent any stages { stage('test') { steps { echo 'some steps' ... -
使用env变量将Jenkins管道中的其他变量设置为代码(Using env variables to set other variables in Jenkins pipeline as code)[2024-03-16]
我不能在下面的访问阶段使用先前块中设置的环境变量。 如果仔细查看错误,可以看到Jenkins实际上无法访问brf ,而不能访问env.city 。 这里的问题是由Jenkins在sh块中解释$var的方式引起的: 如果你使用"double quotes" , sh "... $var ..."将被解释为Jenkins变量; 如果你使用'single quotes' , sh '... $var ...'将被解释为shell变量。 由于脚本中的sh代码包含在"double quotes" ,因此$brf被认为 ... -
使用withEnv动态设置环境变量,以便在管道的某个部分使用(例如,在运行节点脚本时)。 像这样(用你的节点脚本替换sh步骤的内容): pipeline { agent { label 'docker' } environment { ENV1 = 'default' } stages { stage('Set environment') { steps { sh "echo $ENV1" ...