Methods to handle NPM project.
def npm = new Registry(this) // init npm registry npm.init( email : 'artifactory-user@gmail.com', usernamePasswordCredential : 'my-artifactory-credential', registry : 'https://my-project.jfrog.io/my-project/api/npm/npm-release/', scope : 'zowe' )
Modifiers | Name | Description |
---|---|---|
static java.lang.String |
DEFAULT_REGISTRY |
Default npmjs registry. |
static java.lang.String |
NPMRC_FILE |
Constant of .npmrc file name |
static java.lang.String |
PACKAGE_JSON |
Constant of package.json file name |
Type | Name and description |
---|---|
java.util.Map |
_packageInfo Package information extracted from PACKAGE_JSON. |
java.lang.String |
email npm user email, required for publishing |
java.lang.String |
packageJsonFile File name of package.json . |
java.lang.String |
registry npm registry url |
java.lang.String |
scope npm package scope |
java.lang.Object |
steps Reference to the groovy pipeline variable. |
java.lang.String |
tokenCredential Jenkins credential ID for NPM token. |
java.lang.String |
usernamePasswordCredential Jenkins credential ID for NPM username/base64_password |
Constructor and description |
---|
Registry
(java.lang.Object steps) Constructs the class. |
Type Params | Return Type | Name and description |
---|---|---|
|
void |
audit() Run npm audit with default config. |
|
void |
clearPackageInfoCache() Reset package info cache |
|
java.util.Map |
getPackageInfo() Get current package information from package.json . |
|
void |
init(java.util.Map args = [:]) Initialize npm registry properties. |
|
void |
initFromPackageJson(java.util.Map args = [:]) Detect npm registry and scope from package.json . |
|
java.lang.String |
login(java.util.Map args = [:]) Login to NPM registry. |
|
void |
publish(java.util.Map args = [:]) Publish npm package with tag. |
|
void |
resetConfig() Reset NPN configurations. |
|
void |
version(java.util.Map args = [:]) Declare a new version of npm package. |
|
void |
version(org.zowe.jenkins_shared_library.scm.GitHub github, java.lang.String branch, java.lang.String version = 'PATCH') Declare a new version of npm package. |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Default npmjs registry.
"https://registry.npmjs.org/"
Constant of .npmrc
file name
"~/.npmrc"
Constant of package.json
file name
"package.json"
Package information extracted from PACKAGE_JSON.
npm user email, required for publishing
File name of package.json
.
npm registry url
npm package scope
Reference to the groovy pipeline variable.
Jenkins credential ID for NPM token.
Jenkins credential ID for NPM username/base64_password
Constructs the class.
When invoking from a Jenkins pipeline script, the Pipeline must be passed the current environment of the Jenkinsfile to have access to the steps.
def npm = new Registry(this)
steps
- The workflow steps object provided by the Jenkins pipelineRun npm audit with default config.
npm audit
cannot be ran on private registry, so we reset config before audit.Reset package info cache
Get current package information from package.json
.
Expected keys in the result Map:
name
- name of the package. For example, "explorer-jes"
.scope
- scope of the package. Optional. For example, "zowe"
. Please note this value does NOT
have @ included.description
- description of the package if defined. For example, "A UI plugin to handle z/OS jobs."
.version
- version of the package. For example, "1.2.3"
.versionTrunks
- Map version trunks returned from Utils.parseSemanticVersion.license
- license of the package if defined. For example, "EPL-2.0"
.registry
- publish registry of the package if defined.scripts
- List of scripts of the package defined. For example, ["build", "test", "start", "coverage"]
.Initialize npm registry properties.
args
Map.registry
- the registry URLtokenCredential
- Jenkins credential ID for NPM token. Optional.usernamePasswordCredential
- Jenkins credential ID for NPM username/base64_password. Optional.email
- NPM user emailpackageJsonFile
- package.json
file name. Optional, default is PACKAGE_JSON. Detect npm registry and scope from package.json
.
package.json
.Login to NPM registry.
+ npm whoami --registry https://zowe.jfrog.io/zowe/api/npm/npm-release/ npm ERR! code E401 npm ERR! Unable to authenticate, need: Basic realm="Artifactory Realm"
This happens if we set "//zowe.jfrog.io/zowe/api/npm/npm-release/:_authToken"
,
but if we set "_auth=<token>"
, everything is ok.
Is this a bug of Artifactory?
So for now, only usernamePasswordCredential works well.
Publish npm package with tag.
// publish package 1.2.3-snapshot-20190101010101 with dev tag npm.publish( tag : 'dev', version : '1.2.3-snapshot-20190101010101' )
tag
- npm publish tag. Optional, default is empty which is (@code latest).version
- package version to publish.Reset NPN configurations.
Declare a new version of npm package.
def github = new org.zowe.jenkins_shared_library.scm.GitHub(this) // bump patch version on master branch npm.version( github : github, branch : 'master', version : 'patch' ) // After this, you should be able to see your repository master branch has a commit of // version bump.
github
- GitHub instance must have been initialized with repository, credential, etcbranch
- which branch to releaseversion
- what kind of version bump we should makeDeclare a new version of npm package.
Groovy Documentation