Cloud customer?
Start for Free >
Upgrade in MyJFrog >
What's New in Cloud >

Search





Overview

The NpmPublish step publishes an npm package to the registry in Artifactory following an NpmBuild step.


Page Contents


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; https://www.jfrog.com/confluence/display/JFROG/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

integrationsMust specify an Artifactory Integration.Required
inputSteps 

Must specify  a named NpmBuild or Bash step.

Required
outputResources 

Must specify a  BuildInfo  resource if  autoPublishBuildInfo is set to true

If JFROG_CLI_BUILD_NAME or JFROG_CLI_BUILD_NUMBER is set as an environment variable for the pipeline or the input NpmBuild step, that name and/or number will be used for the output BuildInfo. Otherwise, the default buildName and buildNumber are $pipeline_name and $run_number.

May be required


In addition, these tags can be defined to support the step's native operation:

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
deployerRepo The name of the npm repository to publish in Artifactory.Optional
repositoryNameAlternative to  deployerRepo. Do not set both tags.Optional
forceXrayScan

When set to true, forces an Xray scan after publishing to Artifactory.

Default is false.

Optional
failOnScan

When set to  true, and  w hen the Xray  Policy Rule Fail Build  checkbox is checked, a failed Xray scan will result in a failure of the step.

Default is true.

Optional
autoPublishBuildInfo

When set to true, publishes build info to Artifactory.

Default is false.

Optional

execution

Declares collections of shell command sequences to perform for pre- and post-execution phases:

Tag

Description of usage

Required/Optional
onStartCommands to execute in advance of the native operationOptional
onSuccessCommands to execute on successful completionOptional
onFailureCommands to execute on failed completionOptional
onCompleteCommands to execute on any completionOptional


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

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:
          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:
          # 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.

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:
          inputResources:
            - name: gitRepoResource
          integrations:
            - name: artifactory_integration
      - name: npmPublishStep
        type: NpmPublish
        configuration:
          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:
          inputResources:
            - name: gitRepoResource
          integrations:
            - name: artifactory_integration
      - name: npmPublishStep
        type: NpmPublish
        configuration:
          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)

Related Topics

Npm Build Quickstart

  • No labels
Copyright © 2021 JFrog Ltd.