【问题标题】:How to validate the parameter is uppercase in Jenkins using ANT如何使用 ANT 在 Jenkins 中验证参数是否为大写
【发布时间】:2019-08-20 05:28:10
【问题描述】:

我有一个 Jenkins 构建,并且我提供了一个带有大写值的构建参数(构建参数应始终为大写),如果用户提供的是小写值,则构建应该会失败。

请提供有关如何使用 ANT 检查提供的 Jenkins 构建参数是大写还是小写的输入。谢谢!

【问题讨论】:

    标签: jenkins parameters ant uppercase


    【解决方案1】:

    这可以使用 Ant 的matches 条件来完成。下面的示例中使用了嵌套的regexp 以避免重复。

    <target name="check-uppercase">
        <property name="test1" value="lowercase" />
        <property name="test2" value="MixedCase" />
        <property name="test3" value="UPPERCASE" />
    
        <regexp id="all.uppercase" pattern="^[A-Z]+$" />
    
        <condition property="test1.isUppercase" value="true" else="false">
            <matches string="${test1}">
                <regexp refid="all.uppercase" />
            </matches>
        </condition>
    
        <condition property="test2.isUppercase" value="true" else="false">
            <matches string="${test2}">
                <regexp refid="all.uppercase" />
            </matches>
        </condition>
    
        <condition property="test3.isUppercase" value="true" else="false">
            <matches string="${test3}">
                <regexp refid="all.uppercase" />
            </matches>
        </condition>
    
        <echo message="test1 uppercase? ${test1.isUppercase}" />
        <echo message="test2 uppercase? ${test2.isUppercase}" />
        <echo message="test3 uppercase? ${test3.isUppercase}" />
    </target>
    

    【讨论】:

    • 我将从 Jenkins 构建参数中获取大写的值,所以我提到:。但它显示为假,它没有采用我的参数值。对此有什么意见吗?
    • 这取决于您的 Jenkins 作业配置。您使用的是管道,还是带有“调用 Ant”步骤的传统配置?如果是后者,则需要在调用 ant 步骤的“属性”字段中将参数作为属性传递。
    猜你喜欢
    • 1970-01-01
    • 2016-02-25
    • 2020-10-20
    • 1970-01-01
    • 2019-01-23
    • 2019-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多