Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the value of the build parameter ? #34

Closed
Asa6 opened this issue Oct 26, 2021 · 8 comments
Closed

How to get the value of the build parameter ? #34

Asa6 opened this issue Oct 26, 2021 · 8 comments

Comments

@Asa6
Copy link

Asa6 commented Oct 26, 2021

jenkins api:
http://xxxxxx/job/test/descriptorByName/net.uaznia.lukanus.hudson.plugins.gitparameter.GitParameterDefinition/fillValueItems?param=

result:
{"_class":"net.uaznia.lukanus.hudson.plugins.gitparameter.model.ItemsErrorModel","errors":[],"values":[{"name":"4b91af67 2020-10-25 18:11 xxxxx xxxxxxx@xxxx.com 1. xxxxxxxxxxxxxxxxxxxx","value":"4b91af1111115df6212f1fdsfdsaf4223826f43434"}]}

@Asa6 Asa6 changed the title How to get the value of the build parameter How to get the value of the build parameter ? Oct 26, 2021
@Asa6
Copy link
Author

Asa6 commented Oct 26, 2021

job = jk.get_job('test')
for action in job.api_json()['actions']:
for parameter in action['parameterDefinitions']:
print(parameter)

result:
{'_class': 'hudson.model.ParametersDefinitionProperty', 'parameterDefinitions': [{'_class': 'net.uaznia.lukanus.hudson.plugins.gitparameter.GitParameterDefinition', 'defaultParameterValue': {'_class': 'net.uaznia.lukanus.hudson.plugins.gitparameter.GitParameterValue', 'value': '${commit}'}, 'description': None, 'name': '', 'type': 'PT_REVISION'}]}

the result is a variable('value': '${commit}')?

@joelee2012
Copy link
Owner

to get parameters of build with following code

 paramters = build.get_parameters()

@Asa6
Copy link
Author

Asa6 commented Nov 1, 2021

I want to get the optional value of the build parameter before the build, not after the build

similar to this:
image

display a list of optional values ​​for build parameters

@joelee2012
Copy link
Owner

try following code

params = []
for p in job.api_json()['property']:
    if 'parameterDefinitions' in p:
        params = p['parameterDefinitions']

but for your case, the "${commit}" is variable which will be evaluated during building, so you can't get an exact value for job.

@Asa6
Copy link
Author

Asa6 commented Nov 1, 2021

Run the above code, the result is still "${commit}". Is there another way?

@joelee2012
Copy link
Owner

No, because the "${commit}" is bundled with build not the job

@Asa6
Copy link
Author

Asa6 commented Nov 1, 2021

OK, thanks for your answer

@Asa6
Copy link
Author

Asa6 commented Nov 2, 2021

Sorry, it was caused by my jenkins configuration error. Using job.api_json can get the value correctly


params = []
for p in job.api_json()['property']:
if 'parameterDefinitions' in p:
params = p['parameterDefinitions']

Return:
{'name': 'gitchange', 'value': '747d8ddfds2323fdsafdasf239575473bd43254'}

@Asa6 Asa6 closed this as completed Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants