詹金斯dsl中的booleanParam [英] booleanParam in jenkins dsl

查看:260
本文介绍了詹金斯dsl中的booleanParam的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的詹金斯风格的脚本:

I have a jenkins groovy script like this:

    freeStyleJob("test") {
        properties { githubProjectUrl(‘…’) }
        description(‘’’job description’’’.stripMargin('|'))

        logRotator{ numToKeep(100) }

        parameters {
            stringParam(’STRINGP1’, "", "STRINGP1 description")
            stringParam('STRINGP2’, "", "StringP2 description")
            booleanParam(‘b1’, false)
            booleanParam(‘b2’, false)
            booleanParam(‘b3’, false)
            stringParam("EMAIL_LIST", "", "Emails")
        }

        scm {
            github(‘repo’, '${STRINGP1}', 'git', ‘giturl’)
        }

        steps {
            shell '''|#!/bin/bash
                |ARGS=""
                |fi
                |if [[ ‘${b1}’ ]]; then
                |   ARGS=$ARGS" —-p b1"
                |fi
                |if [[ ‘${b2}’ ]]; then
                |   OS_ARGS=$ARGS" —-p b2"
                |fi
                |if [[ ‘${b3}’ ]]; then
                |   ARGS=$ARGS" —-p b3"
                |fi                
                |echo ${ARGS}'''.stripMargin('|')

        }

        publishers {
            archiveArtifacts {
                pattern(‘pattern’)
            }

            extendedEmail {
                ....
                }
            }

        }

    ....
  }

创建作业后,无论用户在UI中选中还是取消选中布尔参数,ARGS的值始终为"--p b1 --- p b2 --p b3".这意味着shell脚本中存在的三个(如果存在)将始终被评估为true.为什么会这样?

After the creation of job no matter whether user checks or unchecks the boolean parameter in the UI, the value for ARGS would be always "--p b1 ---p b2 --p b3". It means that the three if that exist in the shell script will be always evaluated to true. Why does this happen?

推荐答案

envparams中都可以使用参数.当您以$b1身份访问它们时,是从env而不是params获取它们.

Parameters are available from both env and params. When you access them as $b1 you are getting them from env, not params.

所有环境变量就其性质而言都是字符串,因此当您将参数作为环境变量访问时,它们总是 字符串.

All environmental variables are strings by their nature so when you access params as environmental variables, they are always strings.

如果要在键入时访问它们,请使用params:

If you want to access them as they are typed, use params:

script {
  assert env.b1 instanceof String
  assert params.b1 instanceof Boolean
}

这篇关于詹金斯dsl中的booleanParam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆