Git Product home page Git Product logo

Comments (10)

joelee2012 avatar joelee2012 commented on July 18, 2024

@binoyudayan thanks for reporting the issue, i prefer to separate files from params and record in docment

from api4jenkins.

binoyudayan avatar binoyudayan commented on July 18, 2024

hi @joelee2012 ,
You meant get files from params(params.get('files')) and then put the files in resp = self.handle_req('POST', entry, params=params, files=files) in build method itself instead of having a new method?

from api4jenkins.

joelee2012 avatar joelee2012 commented on July 18, 2024

@binoyudayan not really, i mean extract parameter if its value starts with @, then construct files parameter for requests

from api4jenkins.

praczyns avatar praczyns commented on July 18, 2024

Hi @binoyudayan have you managed to send a PR with that? It'd be very useful to be able to create job with file parameter.

from api4jenkins.

binoyudayan avatar binoyudayan commented on July 18, 2024

@praczyns Sorry, I haven't worked on it yet. But I can make a PR.
@joelee2012 Sorry for the late response. But I really didn't get what you mean by this 'extract parameter if its value starts with @, then construct files parameter for requests'

from api4jenkins.

praczyns avatar praczyns commented on July 18, 2024

Thanks, I'm not sure either.

However what I did is I included files as on of the variable length parameters (**params) to build_job, then inside Job build, if 'files' key is in the params dict, I pop it from the dict and pass as files parameter to requests post and pass the rest of the parameters via params. Not super clean as it restricts files from being used as a normal job parameter name but works and it's minimal changes to the library.

I guess what @joelee2012 meant was something between these lines but to also use @ (@files) to distinguish the key as special value?

However I'm affraid that won't work with variable length parameters as AFAIK you cannot have parameter with @ prefix (but you can have dict key starting with @)

from api4jenkins.

binoyudayan avatar binoyudayan commented on July 18, 2024

@praczyns Passing the files key in the params dict will solve the problem. files parameter must be a dictionary I guess to have multiple files. As you have mentioned, this is not clean implementation as this restrict the user from using files key for any other parameter.

Other option is to check the value of each parameter value is file-like and then add them to the files parameter in the post request.

from api4jenkins.

joelee2012 avatar joelee2012 commented on July 18, 2024

@binoyudayan @praczyns my idea is to check value of parameter start with '@' then add them to files parameter, here is snippet

def build(self, **params):
    reserved = ['token', 'delay']
    if not params or all(k in reserved for k in params):
        entry = 'build'
    else:
        entry = 'buildWithParameters'
    # collect file parameter if its value start with '@'
    all_files = []
    for k, v in params.items():
        if v[0] == '@':
            all_files.append((k, ('v[1:]', open('v[1:]', 'rb'))))

    # remove file from paramters
    for file in all_files:
        params.pop(file[0])

    try:
        resp = self.handle_req('POST', entry, params=params, files=all_files)
    finally:
        # eusure file be closed
        for file in all_files:
            file[1][1].close()

    return QueueItem(self.jenkins, resp.headers['Location'])

but i think @binoyudayan 's idea to check file-like is better, how do you think ? and @binoyudayan are you able to make PR ?

from api4jenkins.

binoyudayan avatar binoyudayan commented on July 18, 2024

@joelee2012 sure, I can work on that.

from api4jenkins.

joelee2012 avatar joelee2012 commented on July 18, 2024

As described in https://issues.jenkins.io/browse/JENKINS-47333, Jenkins will not support file parameter, and there is no https://www.jenkins.io/doc/book/pipeline/syntax/#parameters either

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.