Git Product home page Git Product logo

Comments (5)

Sinutok avatar Sinutok commented on August 17, 2024 1

Sorry wasted your time....got it facepalm
I'll post my now running code as example, if someone needs it
jenkins_server = api4jenkins.Jenkins('https://myjenkins.example.com:8443', auth=('someuser','the_api_token'),verify=False)
user = jenkins_server.me.exists()
version = jenkins_server.version
print(str(user))
print(str(version))
job = jenkins_server.get_job("API-TEST - JOB")
print(job)
lauf = job.build(TEXT1="C",TEXT2="lalala")
print(lauf)

Output:
True
2.277.4
<FreeStyleProject: https://myjenkins.example.com:8443/job/API-TEST%20-%20JOB/>
<QueueItem: https://myjenkins.example.com:8443/queue/item/1149/>

and the jenkis job runs correctly with the Parameters: "C" (of the dropdown-box) and "lalala" (of the text-in-field)

from api4jenkins.

joelee2012 avatar joelee2012 commented on August 17, 2024

don't know how do you call the method, but the doc may help https://api4jenkins.readthedocs.io/en/latest/user/example.html#project

from api4jenkins.

Sinutok avatar Sinutok commented on August 17, 2024

I have an example Jenkins-Job which has this Parameter-Definition
.....
"parameterDefinitions" : [
{
"_class" : "hudson.model.ChoiceParameterDefinition",
"defaultParameterValue" : {
"_class" : "hudson.model.StringParameterValue",
"value" : "A"
},
"description" : "Auswahlfeld",
"name" : "TEXT1",
"type" : "ChoiceParameterDefinition",
"choices" : [
"A",
"B",
"C"
]
},
{
"_class" : "hudson.model.TextParameterDefinition",
"defaultParameterValue" : {
"_class" : "hudson.model.StringParameterValue",
"value" : "Das ist ein Test"
},
"description" : "Textfeld",
"name" : "TEXT2",
"type" : "TextParameterDefinition"
}
]
.....
"description" : "API TEST - MG",
"displayName" : "API-TEST - MG",
"displayNameOrNull" : null,
"fullDisplayName" : "API-TEST - MG",
"fullName" : "API-TEST - MG",
"name" : "API-TEST - MG",
.....
"Auswahlfeld == Drop-down/Choice-Field"
"Textfeld == String-Input-Field"

I as your doc statet... I do the following
jenkins_server = api4jenkins.Jenkins('https://lvasp-jenkins.example.com', auth=('myuser','99999tokenid9999'),
verify=False)
job = jenkins_server.get_job("API-TEST - MG")

using
item = job.build_job() produces a
builtins.AttributeError: 'FreeStyleProject' object has no attribute 'build_job'
exception

Using a
payload = "TEXT1=C&TEXT2=LLILI"
header = {'Content-Type': "application/x-www-form-urlencoded"}
lauf = jenkins_server.build_job("API-TEST - MG",headers=header,data=payload)
AFTER changing
....\site-packages\api4jenkins\job.py
Line 137
from: resp = self.handle_req('POST', entry, params=params)
to: resp = self.handle_req('POST', entry, **params)
works like a charm

Propably I get something wrong, but in my opinion the fixed hande_req-parameter 'params' didnt work.
and your documentation of .... arg1='string', arg2='string' is sorry... a litte bit irritating.
How about a real example
Do a freestyle-Job like my one, implement a build-With-Parameters and try it.

(Changed: removed the hasmarks of the posted changed lines)

from api4jenkins.

joelee2012 avatar joelee2012 commented on August 17, 2024

try this :

item = job.build(TEXT1='C', TEXT2='LLILI')

from api4jenkins.

joelee2012 avatar joelee2012 commented on August 17, 2024

yes, i agree with you the doc should be improved, but unfortunately i don't have time recently. i'm happy if you or someone can help on this.

from api4jenkins.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.