Comments (10)
@binoyudayan thanks for reporting the issue, i prefer to separate files
from params
and record in docment
from api4jenkins.
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.
@binoyudayan not really, i mean extract parameter if its value starts with @
, then construct files
parameter for requests
from api4jenkins.
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.
@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.
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.
@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.
@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.
@joelee2012 sure, I can work on that.
from api4jenkins.
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)
- getting jsondecode error HOT 5
- add return type to methods like get_job HOT 1
- get all the configuration properties from a job ? HOT 1
- Build number included string occured error. HOT 5
- Approving the Pending Input is not working when Jenkins runs on Subpath HOT 1
- In Jenkins(jenkins_url, auth=(user,token)), jenkins_url changes port to 80 HOT 2
- proxy agent setting HOT 7
- v1.13 job.get_build(build_number) return None , v1.12 OK HOT 1
- Change node's labels by which api? HOT 2
- Is the library thread-safe? HOT 1
- Please document 100 job limit on get_build(number) HOT 1
- jenkins.get_job().build(with parameters) HOT 2
- Cannot get the specify build use get_build(number) HOT 3
- Unable to store secret file credentials correctly HOT 1
- [FEATURE REQUEST] Credentials domains HOT 2
- v2.0.0 syntax errors when using Python 3.7 due to walrus operator HOT 2
- Unable to control the logger from v.2.0.0 or newer HOT 3
- ResourceWarning: unclosed socket in pytest HOT 3
- WorkflowJob object has no attribute 'get_build' HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from api4jenkins.