在jenkins管道中运行npm安装时出现问题

t8e9dugd  于 2022-11-21  发布在  Jenkins
关注(0)|答案(1)|浏览(278)

我在jenkins管道中运行npm i命令时遇到了麻烦,我已经尝试了几种解决方案,到目前为止都没有成功。
"Jenkins档案"

node {
    env.NODEJS_HOME = "${tool 'node'}"
    env.PATH = "${env.NODEJS_HOME}/bin:${env.PATH}"

    def app
    def workspace = env.WORKSPACE
    def version
    def version_qa
    def app_name = "apresentacao"
    def image_name = "menu"
    def image = "myhub/${image_name}"
    def git_url = "bitbucket.org/myuser/myrepo.git"

    stage('Clone repository') {
        git branch: 'master',
            credentialsId: 'jenkins',
            url: "https://myuser@${git_url}"
    }

    stage('Build') {
        app = docker.build("${image}")         
    }

    stage('Dependencies') {
        // sh 'npm install -g node-gyp'
        sh 'npm config set [--global] devdir /tmp/.gyp'
        sh 'npm install'
    }

    stage('E2E Tests') {
        sh 'npm run exec:e2e'
    }

    stage('Tagging') {
        try {
            withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'jenkins', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {
                sh("echo ${env.GIT_USERNAME}")
                sh("git config --global user.email 'email'")
                sh("git config --global user.name 'Jenkins'")
                sh("git config credential.username ${env.GIT_USERNAME}")
                sh("git config credential.helper '!f() { echo password=\$GIT_PASSWORD; }; f'")
                sh('/opt/tools/create-tag')

                version = sh (script: "stepup version | sed -e 's/v//g'", returnStdout: true).trim()
                echo "next-release: [${version}]"
            }   
        } finally {
            sh("git config --unset credential.username")
            sh("git config --unset credential.helper")
        }

    }

}

错误Jenkins

gyp ERR! node -v v12.6.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
node-gyp exited with code: 1
Please make sure you are using a supported platform and node version. If you
would like to compile fibers on this machine please make sure you have setup your
build environment--
Windows + OS X instructions here: https://github.com/nodejs/node-gyp
Ubuntu users please run: `sudo apt-get install g++ build-essential`
RHEL users please run: `yum install gcc-c++` and `yum groupinstall 'Development Tools'` 
Alpine users please run: `sudo apk add python make g++`
sh: 1: nodejs: not found
npm WARN ts-node@8.3.0 requires a peer of typescript@>=2.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! fibers@3.1.1 install: `node build.js || nodejs build.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the fibers@3.1.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /var/lib/jenkins/.npm/_logs/2019-07-23T03_04_58_311Z-debug.log
hlswsv35

hlswsv351#

似乎故障来自于安装fibers@3.1.1,由于未找到C/C++编译器,遵循其给出的提示安装编译器之前先安装npm install
Windows + OS X操作说明如下:https://github.com/nodejs/node-gyp
Ubuntu用户请运行:sudo apt-get install g++ build-essential
RHEL用户请运行:yum install gcc-c++yum groupinstall'Development Tools'
Alpine用户请运行:sudo apk add pythonmake g++

相关问题