(Getting started question) Want to write a file to Box from a CI/CD pipeline
AnsweredI want to use Box as a repository for documents that I am building in a CI/CD pipeline (circleci.com).
I imagined the process would be something like:
- Download the box-cli as part of Docker setup that runs the CI/CD pipeline
- Obtain an API access key from my box.com (or setup a service user in my org)
- Store the access key as secrets in my CI/CD pipeline config
- At the end of the build process, run the box-cli with the access keys to upload the document
From a bit of looking around the Box API, it seems that I need to:
- Download and build the box-cli along with its node dependencies (there is no install public package for box-cli)
- Create a Box App - I'm unclear on what sort of configuration is required
- Setup OAuth tokens and store them as CI/CD secrets
- Setup some sort of refresh process for the OAuth tokens and update the CI/CD secrets
- At the end of the build process, run the box-cli with the refreshed OAuth tokens to upload the document - somehow this interfaces with the Box App
This seems a lot of pain for a simple use case. Am I on the correct path, or am I missing something?
-
Hi ,
Let me approach this one in a few ways - I'll let you know how I would approach this without the CLI, and then cover a more direct answer on the CLI to your question, if you'd prefer that route:
SDK Method (Recommended)
The way that I would generally approach this is to have a JWT based application that can run from the command line. This would allow you to customize the API requests to Box Platform and that would take care of all of the setup work. If you're using one of the official SDKs then token refresh will be handled for you. The JWT application method will allow you to make API calls to Box behind the scenes without having to have the user log in to Box with their own credentials. You would then have the application run all commands needed
Here's info on setting up an application using that method.
CLI Method (Recommended)
Now for the CLI method. We do have a number of install packages available for the CLI that you can take advantage of. To set up the CLI you can run the box configure:environments:add command and then add in a valid application configuration file. To get this you can create a JWT application, then when you're setting up your keys you can automatically generate it from the application. This will download a config .json file that you can use to import to the CLI. The CLI will also handle token refreshing for you, so you don't have to worry about that.
Hope that helps,
Jon
Please sign in to leave a comment.
Comments
1 comment