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

Search





Overview

The NpmBuild native step builds an npm source. This step automatically performs npm-install on the source in a Git repository. 


If you want to run tests, add a Bash step to trigger them. 

Page Contents


YAML Schema

The YAML schema for NpmBuild native step is as follows:

NpmBuild
pipelines: 
  - name:   <string>
    steps:
      - name: <string>
        type: NpmBuild
        configuration:
          #inherits all the tags from bash; https://www.jfrog.com/confluence/display/JFROG/Bash
          # for payloadType npm:
          npmArgs:          <string>      # optional
          repositoryName:   <string>      # optional, npm repository name on artifactory
          resolverRepo:     <string>      # optional, npm repository name on artifactory
          sourceLocation:   <string>      # optional, directory containing package.json file

          integrations:
            - name:         <artifactory integration>  # required, unless there is a FileSpec input
          inputResources:
            - name:         <gitrepo resource>         # required
            - name:         <filespec 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 NpmBuild 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

integrationsSpecifies an  Artifactory Integration  where modules will be published. If a FileSpec resource is specified in  inputResources  then this is optional. Otherwise, it is required.May be required
inputResources 

Must specify GitRepo   resource. The npm-install runs on  the Git repository at   sourceLocation .

May also optionally specify a  FileSpec  resource that specifies what files to copy to  sourceLocation  prior to running npm-install.

Required

Optional


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
npmArgsSpecifies a command line string of arguments to use with npm-install.Optional
resolverRepo The name of the npm repository in Artifactory.Optional
repositoryName Alternative to  resolverRepo . Do not set both tags.Optional
sourceLocationThe directory containing the package.json file, relative to the GitRepo path. Optional


execution

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

TagDescription of usageRequired/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 NpmBuild step.

Using Default Settings

An NpmBuild step using default locations and default commands.

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

Using FileSpec Input

An NpmBuild step with a FileSpec input providing files for the build that are not in the GitRepo and resolverRepo specifying an Artifactory repository to use when resolving dependencies.

NpmBuild
pipelines: 
  - name: npmBuildPipeline
    steps:
      - name: npmBuildStep
        type: NpmBuild
        configuration: 
          sourceLocation: "source"
          resolverRepo: remote-npm
          inputResources:
            - name: gitRepoResource
            - name: fileSpecResource
          integrations:
            - name: artifactory_integration

How it Works

When you use the NpmBuild native step in a pipeline, it performs the following functions in the background:

  • jfrog rt config (if there is a FileSpec input, to configure the JFrog CLI with the Artifactory credentials in the input FileSpec)
  • jfrog rt use (to set the current default Artifactory configuration )
  • cp (if there is an input FileSpec, copy the files to the root of the cloned GitRepo)
  • jfrog rt npm-config (configure the repository to resolve dependencies)
  • jfrog rt npm-install
  • add_run_variables (save information about this step for future steps)
  • jfrog rt build-collect-env (collect environment variables)
  • add_run_files (save the output and the build information in the run state for later publish steps)

Related Topics

Npm Build Quickstart

  • No labels
Copyright © 2021 JFrog Ltd.