jenkins - 使用复选框或归档时创建动态文本框和密码

问题描述 投票:0回答:1

我想要复选框/单选,当用户选中复选框/使用单选中的字段时,它将动态创建几个文本框(5)。这些文本框中的2个应该包含密码/密钥(因此应该加密/未显示在詹金斯参数中。

我尝试使用 jenkins 文件和 gui 中的 Active Choices 参数和 Active Choices Reactive Reference 参数

示例:

我有参数:

Active Choices Parameter
name: use_custom
Groovy Script:  return ["true", "false"]
Choice Type: single select

Active Choices Reactive Reference Parameter
name: custom_values

Groovy 脚本:

myPassword = ''

if ( use_custom == "true") {

  return """

                    inputBox="<input class='setting-input' name='value' type='password' value=''>"
                    inputBox="<input class='setting-input' name='value' type='text' value=''>"


"""

 echo(text1)


                    

}
else {
 return ""
}

选择类型:格式化 html , 引用参数:use_custom

我创建了2个动态html框(仅适用于文本框,不适用于用户需要手动输入的密码/密钥(不通过jenkins cred)

参数输出示例: 自定义值:1234,11

*它在 jenkins 参数中显示密码(自由文本)

当另一个字段为真(密码不能是自由文本)时允许用户写入密码和文本框(2遍,3框)的解决方案是什么

groovy 管道示例(如果是 Env:dev ,创建 2 个文本框):

properties([
    parameters([
        [$class: 'ChoiceParameter', 
            choiceType: 'PT_SINGLE_SELECT', 
            description: 'Select the Env Name from the Dropdown List', 
            filterLength: 1, 
            filterable: true, 
            name: 'Env', 
            randomName: 'choice-parameter-5631314439613978', 
            script: [
                $class: 'GroovyScript', 
                fallbackScript: [
                    classpath: [], 
                    sandbox: false, 
                    script: 
                        'return[\'Could not get Env\']'
                ], 
                script: [
                    classpath: [], 
                    sandbox: false, 
                    script: 
                        'return["Dev","QA","Stage","Prod"]'
                ]
            ]
        ], 
        
        
        // [$class: 'CascadeChoiceParameter', 
        //     choiceType: 'ET_FORMATTED_HTML', 
        //     description: 'Select the Server from the Dropdown List', 
        //     filterLength: 1, 
        //     filterable: true, 
        //     name: 'Server', 
        //     randomName: 'choice-parameter-5631314456178619', 
        //     referencedParameters: 'Env', 
        
        [$class: 'DynamicReferenceParameter',
        choiceType: 'ET_FORMATTED_HTML',
        omitValueField: true,
        description: '123',
        name: 'Server',
        randomName: 'choice-parameter-5631314456178624',
        referencedParameters: 'Env',
            script: [
                $class: 'GroovyScript', 
                fallbackScript: [
                    classpath: [], 
                    sandbox: false, 
                    script: 
                        'return[\'Could not get Environment from Env Param\']'
                ], 
                script: [
                    classpath: [], 
                    sandbox: false, 
                    script: 
                        ''' if (Env.equals("Dev")){
                        inputBox2 = "<input name='value' class='setting-input' type='text'>"
                        inputBox = "password(name: 'KEY', description: 'Encryption key')"

                        

return[inputBox]                          
}
else {
 return ""
}
                        '''
                ]
            ]
        ],
        
        
        [$class: 'DynamicReferenceParameter',
        choiceType: 'ET_FORMATTED_HTML',
        omitValueField: true,
        description: '1234',
        name: 'pass',
        //randomName: 'choice-parameter-5631314456178624',
        referencedParameters: 'Env',
            script: [
                $class: 'GroovyScript', 
                fallbackScript: [
                    classpath: [], 
                    sandbox: false, 
                    script: 
                        'return[\'Could not get Environment from Env Param\']'
                ], 
                script: [
                    classpath: [], 
                    sandbox: false, 
                    script: 
                        ''' if (Env.equals("Dev")){
                        inputBox = "<input name='value' class='setting-input' type='password'>"

return[inputBox]                          
}
else {
 return ""
}
                        '''
                ]
            ]
        ]
        

        
        
    ])
])

pipeline {
  environment {
         vari = ""
  }
  agent any
  stages {
      stage ("Example") {
        steps {
         script{
          echo 'Hello'
          echo "${params.Env}"
          echo "${params.Server}"
        echo "${params.pass}"

          if (params.Server.equals("Could not get Environment from Env Param")) {
              echo "Must be the first build after Pipeline deployment.  Aborting the build"
              currentBuild.result = 'ABORTED'
              return
          }
          echo "Crossed param validation"
        } }
      }
  }
}

我也尝试过使用 mask_plugin ,它从控制台输出中屏蔽,而不是从参数中屏蔽,有什么想法吗? 谢谢

jenkins jenkins-pipeline jenkins-plugins
1个回答
0
投票

你尝试过吗

<label for="pwd">Password:</label>
<input type="password" id="pwd" name="pwd" minlength="8"><br><br>
© www.soinside.com 2019 - 2024. All rights reserved.