26 May 2018 | tags: Jenkins npm swagger openapi
Installation
Ensure npm is installed. In the shell, simply run this:
npm install -g swagger-cli
Usage
To validate swagger files (in yaml format) we use swagger-cli
, if the file validates then it can be published safely.
Its usage is really simple, one would simply run (assuming the file to checked is transaction-services.yml
) this:
swagger-cli validate transaction-services.yml
If the file validates, its return code will be 0, otherwise it will return 1. Please do not use the stdout or stderr, that’s not the right way
to check the return of a command in UNIX.
13 May 2018 | tags: Jenkins npm
When building a project that uses npm, one of the first things to do is to install the needed npm modules under $PROJECT/npm_modules. That is accomplished with npm install. But that is quite time consuming, if we’re using a CI system like Jenkins or Travis that can slow down the builds a lot.
Since npm 5.7.0, there’s a new option: npm ci. That new option is used to improve the installation of modules in CI systems. Bottom line is that it uses the modules under ${HOME}/.npm, it skips some user oriented checks. However it does more strict checks used to catch inconsistencies.
Essentially, the differences between npm install and npm ci are:
- The project must have an existing package-lock.json or npm-shrinkwrap.json.
- If dependencies in the package lock do not match those in package.json, npm ci will exit with an error, instead of updating the package lock.
- npm ci can only install entire projects at a time: individual dependencies cannot be added with this command.
- If a node_modules is already present, it will be automatically removed before npm ci begins its install.
- It will never write to package.json or any of the package-locks: installs are essentially frozen.
That way, it saves you from checking if the contents of package.json have changed and keeping a copy of node_modules outside the project directory. Until now I had to keep a copy of the node_modules directory needed in my projects outside the Jenkins scope; when firing a build a special pipeline step had to check whether the package.json had changed and then that step had to copy the node_modules. Dirty work and very error prone. With npm ci I don’t have to do that anymore.
07 May 2018 | tags: Jenkins nginx
If having an nginx in front of Jenkins (or any other agent performing authentication) we may fall into problems if the user used in the front nginx proxy is not the same the agent behind it has. The problem is that the nginx in
proxy_set_header Authorization "";