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

Added docs and js example for REST API usage #104

Merged
merged 8 commits into from
May 18, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ You can use Base64 parameters for passing _small_ files to downstream builds:
build job: 'downstream', parameters: [base64File(name: 'file', base64: Base64.encoder.encodeToString('hello'.bytes)))]
```

## Usage with REST API

You can pass file parameters to the REST API:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildWithParameters, especially with file uploads, seems to strain the definition of https://en.wikipedia.org/wiki/Representational_state_transfer#Architectural_constraints. https://www.jenkins.io/doc/book/using/remote-access-api/ does refer to a REST-like style though actually this refers to the read-only “export” system https://javadoc.jenkins.io/component/stapler/org/kohsuke/stapler/export/package-summary.html + https://javadoc.jenkins.io/hudson/model/Api.html. Nitpicking but maybe the wording can be relaxed to just say a “remote” or “HTTP” API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can certainly do that. Although since Jenkins itself seems to refer to buildWithParameters as part of their REST API, it will probably be a good idea to at least have that name in a parenthetical note to help people to land in a successful conclusion


```js
const file = fileInput.files[0]; // a File object
const body = new FormData();
body.append('ICON_FILE', file); // will come through to the job as the named file parameter 'ICON_FILE'
gwynjudd marked this conversation as resolved.
Show resolved Hide resolved
const request = new Request(`${buildAPI}buildWithParameters`, { method: 'POST', body });
gwynjudd marked this conversation as resolved.
Show resolved Hide resolved
fetch(request); // omitted, crumb header and other credentials
gwynjudd marked this conversation as resolved.
Show resolved Hide resolved
```

## LICENSE

Licensed under MIT, see [LICENSE](LICENSE.md)