NPM and Yarn Wrapper and Steps

ID: npm-yarn-wrapper-steps

This is a pipeline-friendly Jenkins plugin that provides an npm wrapper, a yarn wrapper and npm and yarn build steps for Unix systems. If NodeJS and/or Yarn are not available, it installs them on demand using nvm and the yarn classic installation script. If there is an .nvmrc file in the directory where the commands are to be executed, it respects the version specified there. Otherwise, it uses the latest stable version of NodeJS. The wrapper allows specifying a workspace subdirectory (to provide an .npmrc file) and providing login credentials.

NPM Credentials

Users can provide credentials for a private or corporate NPM repository by setting them up through the custom NPM Credential type. To do so, navigate to manage credentials within Jenkins and provide the appropriate url, username, user email and password.

Select NPM Login Credentials as the credential kind.

Fill in the form with the correct credentials for your Artifactory. Note that currently no validation is done to ensure that the credentials are correct prior to storing them.

Fill in the appropriate login information.

Wrapper in Freestyle Projects

To set up the wrapper, select an NPM Login Credential and, optionally, set a subdirectory of the workspace to use when setting up NodeJS. The primary reason to add a workspace subdirectory to the wrapper is if you're using an .nvmrc file to manage your NodeJS version.

Select a credential and provide a workspace subdirectory

Steps in Freestyle Projects

Both npm and yarn build steps are provided. If no wrapper is provided, the plugin will attempt to set up nvm, NodeJS and yarn (for yarn build steps) based on the .nvmrc in the working directory or the subdirectory (if specified). If no .nvmrc is present, it will use the current release of NodeJS.

Select Run a yarn command or Run an npm command

NPM Step

The npm step supports anything that completes npm run #{your command here}. If you provide a subdirectory, the command will be executed from that subdirectory of the workspace.

Enter an npm command

Yarn Step

The yarn step supports anything that completes yarn #{your command here}. If you provide a subdirectory, the command will be executed from that subdirectory of the workspace.

Enter a yarn command

Wrapper in Pipelines

The plugin includes a special credential type for npm, which is used in the wrapper to support private npm repositories.

pipeline {
    agent any
    stages {
        stage('Hello') {
            steps {
                withNPMWrapper('MyCredential') {
                    npm 'init -y'
                    npm command: 'publish'
                }
            }
        }
    }
}

Steps in Pipelines

This plugin provides steps for use in Jenkins Pipelines. They will install nvm if not already installed and will use the version of NodeJS specified in the project's .nvmrc file. The steps accept a raw command to passed to yarn or npm run and, optionally, a subdirectory of the workspace from which to execute the command. If no subdirectory is provided, the steps assume the root of the workspace.

pipeline {
    agent any
    stages {
        stage('Hello') {
            steps {
                yarn 'init -y'
                npm 'view react'
            }
        }
        stage('Hello with subdirectories') {
            steps {
                yarn command: 'init -y', workspaceSubdirectory 'some-subdirectory'
                npm command: 'view react', workspaceSubdirectory 'some-other-subdirectory'
            }
        }
    }
}
ArchivesGet past versions
Version: 0.0.1
Released:
Requires Jenkins 2.277.1
Installs: No usage data available
Labels
This plugin has no labels
Maintainers
James
Help us improve this page!
To propose a change submit a pull request to the plugin page on GitHub.