jenkinsci / persistent-parameter-plugin

https://plugins.jenkins.io/persistent-parameter/
MIT License
7 stars 11 forks source link

Question: How to use this with pipelines? #8

Open ThomasStubbe opened 4 years ago

ThomasStubbe commented 4 years ago

How do you use this with pipeline? I can't find any docs nor snippets

pipeline {
    agent {
        label '...'
    }
    parameters {
        gitParameter branchFilter: 'origin/(.*)', name: 'branch', ...
        persistentStringParameter(defaultValue: 'default', description: 'gimme info', name: 'someParam')
    }

It results in: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 7: Invalid parameter type "persistentStringParameter". Valid parameter types: [booleanParam, choice, credentials, file, gitParameter, listGitBranches, text, password, run, string] @ line 7, column 9.

kshaa commented 4 years ago

I also wanted to use this, but I guess declarative pipelines aren't supported?

kshaa commented 4 years ago

@ThomasStubbe I found out how to use these in a declarative pipeline. It turns out this plugin doesn't do what I want, but here's the code for you if you need it.

// Properties/Parameters
properties([[
    $class: 'ParametersDefinitionProperty',
    parameterDefinitions: [
        [
            $class: 'PersistentStringParameterDefinition',
            name: 'a',
            description: 'String'
        ],
        [
            $class: 'PersistentBooleanParameterDefinition',
            description: 'Boolean',
            name: 'b'
        ]
    ]
]])

pipeline {
[...]
  stages {
        stage('Stage') {
            steps {
                script {
                    sh 'echo "a parameter: ${params.a}"'
                }
            }
        }
    }
  }
}

But this overrides the pipeline.parameters for some reason. At least this may be a step forward for you.

tinmarino commented 4 years ago

Still no idea: There is a discussion on StackOverflow

uglyliu commented 3 years ago

i solved this problem, my Jenkins vesion is 2.222 ,Pipleine2.0, Persistent Parameter Plugin1.2 the following is the my case

properties([
 parameters([
         [$class: 'PersistentChoiceParameterDefinition', choices: '3\n1\n2\n3\n4\n5\n6\n7\n8\n10', description: '选择需要部署的pod数量', name: 'POD_NUM', successfulOnly: false],
         [$class: 'PersistentChoiceParameterDefinition', choices: '4000\n5000\n6000\n7000\n8000\n9000\n1000\n2000\n3000', description: '选择Request CPU 单位【m】', name: 'Limit_Request_CPU', successfulOnly: false],
     [$class: 'PersistentChoiceParameterDefinition', choices: '16000\n17000\n18000\n190000\n20000\n15000\n14000\n13000\n12000\n10000', description: '选择Limit CPU 单位【m】', name: 'Limit_Max_CPU', successfulOnly: false],
     [$class: 'PersistentChoiceParameterDefinition', choices: '20\n30\n40\n50\n60\n10\n8\n6\n4\n2', description: '选择Request Memory 单位【Gi】', name: 'Limit_Request_Mem', successfulOnly: false],
     [$class: 'PersistentChoiceParameterDefinition', choices: '40\n50\n60\n70\n80', description: '选择Limit Memory 单位【Gi】】', name: 'Limit_Max_Mem', successfulOnly: false],
     [$class: 'PersistentChoiceParameterDefinition', choices: '3\n4\n5\n6\n2\n1', description: 'Hpa最小副本数', name: 'Limit_Min_Counts', successfulOnly: false],
     [$class: 'PersistentChoiceParameterDefinition', choices: '6\n7\n8\n9\n10', description: 'Hpa最大副本数', name: 'Limit_Max_Counts', successfulOnly: false]
  ]
  )
])
arungitan commented 3 years ago

i solved this problem, my Jenkins vesion is 2.222 ,Pipleine2.0, Persistent Parameter Plugin1.2 the following is the my case

properties([
 parameters([
         [$class: 'PersistentChoiceParameterDefinition', choices: '3\n1\n2\n3\n4\n5\n6\n7\n8\n10', description: '选择需要部署的pod数量', name: 'POD_NUM', successfulOnly: false],
         [$class: 'PersistentChoiceParameterDefinition', choices: '4000\n5000\n6000\n7000\n8000\n9000\n1000\n2000\n3000', description: '选择Request CPU 单位【m】', name: 'Limit_Request_CPU', successfulOnly: false],
   [$class: 'PersistentChoiceParameterDefinition', choices: '16000\n17000\n18000\n190000\n20000\n15000\n14000\n13000\n12000\n10000', description: '选择Limit CPU 单位【m】', name: 'Limit_Max_CPU', successfulOnly: false],
   [$class: 'PersistentChoiceParameterDefinition', choices: '20\n30\n40\n50\n60\n10\n8\n6\n4\n2', description: '选择Request Memory 单位【Gi】', name: 'Limit_Request_Mem', successfulOnly: false],
   [$class: 'PersistentChoiceParameterDefinition', choices: '40\n50\n60\n70\n80', description: '选择Limit Memory 单位【Gi】】', name: 'Limit_Max_Mem', successfulOnly: false],
   [$class: 'PersistentChoiceParameterDefinition', choices: '3\n4\n5\n6\n2\n1', description: 'Hpa最小副本数', name: 'Limit_Min_Counts', successfulOnly: false],
   [$class: 'PersistentChoiceParameterDefinition', choices: '6\n7\n8\n9\n10', description: 'Hpa最大副本数', name: 'Limit_Max_Counts', successfulOnly: false]
  ]
  )
])

when I tried this, I got "WorkflowScript: 32: The ‘properties’ section has been renamed as of version 0.8. Use ‘options’ instead." we have jenkins 2.273 ( no idea how to get the versions of plugins etc. - i am not jenkins admin. ) Any idea how to achieve the same thing using options block?

arungitan commented 3 years ago

and if I attempt it with the options block like so: options { parameterDefinitions([ ... ]) } it seems like options doesn't know about parameters at all: WorkflowScript: 33: Invalid option type "parameterDefinitions". Valid option types: [authorizationMatrix, buildDiscarder, catchError, checkoutToSubdirectory, copyArtifactPermission, disableConcurrentBuilds, disableResume, durabilityHint, lock, newContainerPerStage, overrideIndexTriggers, parallelsAlwaysFailFast, preserveStashes, quietPeriod, rateLimitBuilds, retry, script, skipDefaultCheckout, skipStagesAfterUnstable, timeout, timestamps, waitUntil, warnError, withChecks, withContext, withCredentials, withEnv, wrap, ws] @ line 33, column 9.

ro-kr commented 3 years ago

Declarative pipeline support has been implemented by #12 and is part of plugin release 1.3.