The NpmPublish step publishes an npm package to the registry in Artifactory following an NpmBuild step. It is recommended, but not required, that the NpmBuild and NpmPublish steps be in the same affinity group to optimize sharing files between the two steps.
Important
The NpmPublish native step may fail on W19 nodes when JFrog CLI v1 is used. Workaround is to use JFrog CLI v2.
Important
The NpmPublish
native step uses Node runtime image by default. If runtime image of any other type is configured at pipeline-level for this native step, it will be ignored.
YAML Schema
The YAML schema for NpmPublish native step is as follows:
NpmPublish
pipelines: - name: <string> steps: - name: <string> type: NpmPublish configuration: #inherits all the tags from bash # for payloadType npm: deployerRepo: <string> # optional, npm repository name on artifactory repositoryName: <string> # optional, npm repository name on artifactory forceXrayScan: <boolean> # optional failOnScan: <boolean> # default true autoPublishBuildInfo: <boolean> # optional integrations: - name: <artifactory integration> # required inputSteps: - name: <NpmBuild step> # required outputResources: - name: <BuildInfo resource> # optional execution: onStart: - echo "Preparing for work..." onSuccess: - echo "Job well done!" onFailure: - echo "uh oh, something went wrong" onComplete: #always - echo "Cleaning up some stuff"
Tags
name
An alphanumeric string (underscores are permitted) that identifies the step.
type
Must be NpmPublish
for this step type.
configuration
Specifies all configuration selections for the step's execution environment. This step inherits the Bash/ PowerShell step configuration tags, including these pertinent tags:
Tag | Description of usage | Required/Optional |
---|---|---|
| Must specify an Artifactory Integration. | Required |
| Required | |
| Must specify a BuildInfo resource if If | May be required |
In addition, these tags can be defined to support the step's native operation:
Note
All native steps derive from the Bash step. This means that all steps share the same base set of tags from Bash, while native steps have their own additional tags as well that support the step's particular function. So it's important to be familiar with the Bash step definition, since it's the core of the definition of all other steps.
Tag | Description of usage | Required/Optional |
---|---|---|
| The name of the npm repository to publish in Artifactory. | Optional |
| Alternative to | Optional |
| When set to Default is | Optional |
| When set to Default is | Optional |
| When set to Default is | Optional |
execution
Declares collections of shell command sequences to perform for pre- and post-execution phases:
Tag | Description of usage | Required/Optional |
---|---|---|
| Commands to execute in advance of the native operation | Optional |
| Commands to execute on successful completion | Optional |
| Commands to execute on failed completion | Optional |
| Commands to execute on any completion | Optional |
The actions performed for the onExecute
phase are inherent to this step type and may not be overridden.
Examples
The following examples show how to configure an NpmPublish step.
Full Pipeline Example
This example requires a GitHub Integration.
The Pipelines DSL for this example is available in this repository in the JFrog GitHub account.
For more information about running this example, see Pipeline Example: Npm Build.
NpmBuild
# This config file is templatized so that it can be easily customized. Values can be provided with a values.yml file. template: true # required for local templates valuesFilePath: ./values.yml resources: - name: npm_repo_jfp_example type: GitRepo configuration: # SCM integration where the repository is located gitProvider: {{ .Values.myRepo.gitProvider }} # Repository path, including org name/repo name path: {{ .Values.myRepo.path }} branches: # Specifies which branches will trigger dependent steps include: master - name: npm_buildinfo_jfp_example type: BuildInfo configuration: sourceArtifactory: demoArt pipelines: - name: npm_pipeline_jfp_example steps: - name: npm_build_step type: NpmBuild configuration: affinityGroup: npm_pipeline_jfp_example repositoryName: npm-virtual # required, npm repository name on artifacctory sourceLocation: . # required, location of package.json file integrations: - name: demoArt # required inputResources: - name: npm_repo_jfp_example # required - name: npm_publish_step type: NpmPublish configuration: affinityGroup: npm_pipeline_jfp_example # for payloadType npm: repositoryName: npm-virtual # required, npm repository name on artifactory autoPublishBuildInfo: true # optional integrations: - name: demoArt # required inputSteps: - name: npm_build_step # required outputResources: - name: npm_buildinfo_jfp_example # optional
Upload Artifactory Repo
Uploads to an Artifactory repository named npm-repo.
Note
This example is not a complete pipeline. An NpmBuild step must be part of the same pipeline.
NpmPublish
pipelines: - name: npmPublishPipeline steps: - name: npmPublishStep type: NpmPublish configuration: deployerRepo: npm-repo integrations: - name: artifactory_integration inputSteps: - name: npmBuildStep
Upload the Result of NpmBuild Step to Artifactory Repo
Uploads the result of the NpmBuild step to an Artifactory repository named npm-repo and uploads build info. This extends example 1 in the NpmBuild documentation.
NpmPublish
pipelines: - name: npmBuildPipeline steps: - name: npmBuildStep type: NpmBuild configuration: affinityGroup: npmBuildPipeline inputResources: - name: gitRepoResource integrations: - name: artifactory_integration - name: npmPublishStep type: NpmPublish configuration: affinityGroup: npmBuildPipeline deployerRepo: npm-repo autoPublishBuildInfo: true inputSteps: - name: npmBuildStep outputResources: - name: outputBuildInfo
Publish Build Info and Trigger Xray Scan
In this example, build info is published and an Xray scan triggered.
NpmPublish
pipelines: - name: npmBuildPipeline steps: - name: npmBuildStep type: NpmBuild configuration: affinityGroup: npmBuildPipeline inputResources: - name: gitRepoResource integrations: - name: artifactory_integration - name: npmPublishStep type: NpmPublish configuration: affinityGroup: npmBuildPipeline deployerRepo: npm-repo autoPublishBuildInfo: true forceXrayScan: true inputSteps: - name: npmBuildStep outputResources: - name: outputBuildInfo
How it Works
When you use the NpmPublish native step in a pipeline, it performs the following functions in the background:
jfrog rt use (specify the configured credentials to use)
restore_run_files (copy the output and build info from the NpmBuild step)
jfrog rt npm-config (configure the deploy repo)
jfrog rt npm-publish
jfrog rt build-publish (if autoPublishBuildInfo is true, publish the build info)
write_output (if autoPublishBuildInfo is true, update the output BuildInfo resource)
jfrog rt build-scan (if forceXrayScan is true, trigger a scan)
add_run_files (update the build info saved in run state)