Unable to deploy a node.js package via a jenkins job

I'm looking to set up a Jenkins job that will publish a package to npmjs.com. The source code for the package is located in a GitHub repository.

While I am able to successfully publish the package from my personal computer by running 'npm publish' in the console, I encounter an error when attempting to do so through Jenkins.

This is the setup of my Jenkins job:

  • Specified path to the GitHub project

  • Added an 'Execute Windows batch command' with the following script:

git checkout master
git pull
npm publish

The output in the console looks like this:

C:\Program Files (x86)\Jenkins\workspace\js-agent-cucumber-release>git checkout master 
Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
Previous HEAD position was fbd7040 Update package.json
Switched to branch 'master'

C:\Program Files (x86)\Jenkins\workspace\js-agent-cucumber-release>git pull 
Updating 27de403..fbd7040
Fast-forward
 package.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

[Remaining console output removed for brevity]

Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE

Is there anyone who has encountered this issue before and knows how to resolve it?

Answer №1

After numerous attempts, I have successfully established a pipeline for releasing my package on npmjs. The process included the following steps:

  1. Create a Jenkins job with the 'Pipeline' type.

  2. In the 'Pipeline' section, select 'Pipeline script from SCM'.

  3. Specify the repository type and provide the path to your repo.

  4. Include a file named "Jenkinsfile" at the root of your project containing the script below.

pipeline {

    agent {

        docker {
            image 'node:10-alpine' 
            args '-u root' 
        }
    }

    stages {

        stage('Install') { 
            steps {
                sh 'npm install' 
            }
        }
        stage('Publish') { 

            steps {

                load "$JENKINS_HOME/jobvars.env"

                withEnv(["TOKEN=${NPMJS_TOKEN}"]) {

                    sh 'echo "//registry.npmjs.org/:_authToken=${TOKEN}" >> ~/.npmrc'
                    sh 'npm publish' 

                }
            }
        }
    }
}
  1. Create a "jobvars.env" file in the folder where Jenkins is installed and include the following line:
NPMJS_TOKEN="token-generated-on-npmjs-com-in-your-profile"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering error 400 in Ionic 3 when trying to add platforms

Currently in the process of migrating from one system to another, I have cloned the code from my git repository onto my new system. To deploy an application on this new platform, I attempted to add platforms by running both npm install and ionic cordova pl ...

What could be causing the issue with the focus not being activated when clicking on the input field in Vue?

I am facing an issue where I have to click twice in order to focus on a specific input field, and I'm having trouble setting the cursor at the end of the input. I attempted to use $refs, but it seems like there may be a deeper underlying problem. Any ...

Steps to load data using ajax-php with specific parameters

I have a situation where I need to trigger a JavaScript function when a link is clicked. <input type='hidden' id='name'> <a href='#' onclick='getUsers(1)'>Click here</a> function getUsers(id){ $( ...

Arrange arrays with multiple dimensions in JavaScript based on their ranges

Seeking assistance on sorting a multi-dimensional array returned from an API to enable users to choose a range based on beats. I'm currently facing challenges with the data my API is returning. var myObj = [{ title: 'title one', be ...

Idea: Develop a bookmarklet that generates a header form and deletes it upon submission

After much contemplation and experimentation, I have been grappling with the idea of creating a bookmarklet that displays a header when clicked on any webpage. This header will contain a small form that submits its contents to a server before disappearing. ...

Guide on starting a development server in Laravel Mix (solo project)

I want to run my project on a server to view it in the browser. Currently, I am using npx mix watch --hot which starts my project at localhost:8080. However, this command enables hot reload. Is there a way to start the server without enabling hot reloadin ...

Planes in Three.js that are overflowing may have their opacity adjusted

My current challenge involves aligning two planes in the same (or closest possible) position. When two planes made of different materials and colors occupy the same space, depending on the camera angle and view perspective, the front plane's opacity ...

Ways to update an angular page using the router without resorting to window.location.reload

I have a specific method for resetting values in a component page. The process involves navigating from the "new-edition" page to the "my-editions" component and then returning to the original location at "new-edition". I am currently using this approach ...

How can I create my own unique scrolling behavior in JavaScript?

Looking to create a similar effect as seen on this website: where the vertical scrollbar determines the movement of the browser "viewport" along a set path. I believe that using Javascript to track the scroll bar value and adjust background elements acco ...

Insert a numerical value into a list to make a series of numbers whole

I currently have an array of objects that looks like this: var arr = [ { "code": "10", }, { "code": "14", } ] My goal is to expand this array to contain 5 elements. The numbers should ran ...

Browserify is having trouble locating the npm module

I'm encountering great difficulty while trying to develop an NPM module: react-smallgrid import React from 'react'; import _ from 'lodash'; export default class SmallGrid extends React.Component{ After compilation: browserify: ...

Generating elements added at various depths within an HTML document with the help of JavaScript

create_new.append("div") .append("form").merge(update_5) .attr("action", d => d.market) .attr("target","_blank") .style("width","100%") .style("height","282") .append("input").merge(update_5) .attr("type","submit") ...

The ajaxStart event does not seem to be triggering when clicked on

I am having trouble adding a loader to my site using the ajaxStart and ajaxStop requests to show and hide a div. The issue is that these requests are not being triggered by button onclick events. <style> // CSS for loader // Another class with o ...

Having trouble detecting the Selection event of a Dropdown List upon loading

When a user chooses an option from the dropdown menu, I need to capture the selected item and perform an action: $("#user-list").on("change", function() { var selectedUser = $(this).find(":selected").text(); // Perform action with the selected us ...

Leveraging the AngularJS model within a tabset framework

I am working with a tabset that has two options and I am binding data from a JSON file using Angular. What I would like to do is log the name of the tab that I click on to the console. I thought about using a "model" for this, but I am not sure if that is ...

Steps to resolve the Angular observable error

I am trying to remove the currently logged-in user using a filter method, but I encountered an error: Type 'Subscription' is missing the following properties from type 'Observable[]>': _isScalar, source, operator, lift, and 6 more ...

Displaying minute scale from right to left using jQuery technology

I successfully created a minute scale that is functioning well, but now I am encountering an issue with displaying my scale. Instead of being oriented left to right, I would like it to be displayed from right to left. Can anyone suggest what might be wron ...

Animated CSS Checkmark Design

How can I create an animated Check-mark using CSS with SVG animation? I attempted the following code but it doesn't seem to be working. Any suggestions? DEMO: https://jsfiddle.net/b7Ln0jns/ CSS: @import "bourbon"; $color--green: #7ac142; $curve: c ...

Ways to resolve issues related to null type checking in TypeScript

I am encountering an issue with a property that can be null in my code. Even though I check for the value not being null and being an array before adding a new value to it, the type checker still considers the value as potentially null. Can anyone shed lig ...

What is causing the jQuery functions to not be executed in sequence?

Whenever I click the Start button, my function is supposed to run a cycle for 10 iterations. Each iteration generates a number between 1 and 7, which then triggers a series of functions on different objects. The problem is that these functions are not runn ...