Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Latest commit

 

History

History
137 lines (104 loc) · 4.02 KB

execNpm.md

File metadata and controls

137 lines (104 loc) · 4.02 KB

execNpm

The execNpm steps enables you to NPM builds within your pipeline scripts. The step supports the managed file auto lookup mechanism so you don't have to configure your own npm artifact manager in every job.

Table of contents

Managed file auto lookup

The managed file auto lookup is the core functionality of the execNpm step. It reduces the amount of time that must be spend for configuring npm builds in larger environments to a minimum.

NPM/node.js environment configuration

If you are using node.js/NPM to build frontend stuff within your ci environment you can use the execNpm step to automatically provide

  • managed configuration file to NPM_CONFIG_USER_CONFIG environment variable
  • managed configuration file to NPMRC environment variable

Example for NPM_CONFIG_USER_CONFIG and NPMRC auto lookup

Given a company with a GIT server at https://git.company.tld, a npmrc setting with id group1-project1-npmrc and a npm config with id group1-project1-npm-config stored inside Jenkins as ManagedFile.

When you setup your own pipeline library which uses the pipeline-library all you have to do is to create the file resources/managedfiles/npm/npmrc.json with this content:

[
  {
    "pattern": "git.company.tld/group1/project1",
    "id": "group1-project1-npmrc",
    "name": "group1, project1 npmrc",
    "comment": "npmrc for group1/project1"
  }
]

and a file resources/managedfiles/npm/npm-config-userconfig.json with this content:

[
  {
    "pattern": "git.company.tld/group1/project1",
    "id": "group1-project1-npm-config",
    "name": "group1, project1 npm config",
    "comment": "npmrc for group1/project1"
  }
]

When you now execute the execNpm Step with

import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*
execNpm(
    (SCM) : [ (SCM_URL) : 'https://git.company.tld/group1/project1.git' ],
    (NPM) : [ (NPM_ARGUMENTS): ['run', 'build'] ]
)

Npm will be executed with this commandline:

npm run build --userconfig /path/to/user/config --globalconfig / path/to/global/config

Examples

Configuration options

Complete list of all configuration options.

All configuration options must be inside the npm (ConfigConstants.NPM) map element to be evaluated and used by the step.

import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*

execNpm( 
    (NPM) : [
        (NPM_ARGUMENTS): [ "run", "build" ],
        (NPM_EXECUTABLE): "npm",
    ]
)

arguments

Constant ConfigConstants.NPM_ARGUMENTS
Type List of String or String
Default []

The arguments which will be placed after the npm command.

(NPM_ARGUMENTS) : [ "run", "build" ]

or a String like:

(NPM_ARGUMENTS) : [ "run build" ]

executable (optional)

Constant ConfigConstants.NPM_EXECUTABLE
Type Map or String
Default null

Defines the executable to use. Per default execNpm expects the executable npm to be in the PATH

Related classes