问题
Background:
We have node version 8 installed and is working fine in a Jenkins alpine based docker image (running in AWS ECS). The node 8 was installed in the jenkins-alpine docker image.
Then, there came another requirement to install node js Jenkins plugin, so that custom version can be installed and applied as needed using global tools configuration, We installed nodejs 10 as shown in the image below:
Nodejs Plugin failed to run in jenkins
I then tried using the jenkins nodejs 10 plugin in jenkins pipeline as follows:
#!groovy
pipeline {
options {
buildDiscarder(logRotator(daysToKeepStr: '5'))
timeout(time: 5, unit: 'MINUTES')
ansiColor('xterm')
}
agent {
label 'jenkins-slave'
}
stages {
stage('Nodejs test') {
steps {
nodejs('NodeJS 10.19.0') {
sh "which node; which npm"
sh "ls -l /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node"
sh "node -v"
}
}
}
}
}
}
The jenkins job failed as it could not find node even though it did exist and was executable:
11:00:31 + which node
11:00:31 /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node
11:00:31 + which npm
11:00:31 /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/npm
[Pipeline] sh
11:00:31 + ls -l /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node
11:00:31 -rwxrwxr-x 1 jenkins jenkins 41122344 Feb 5 23:36 /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node
11:00:32 + /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node -v
11:00:32 /var/jenkins_home/workspace/test-jerald-nodejs-plugin@tmp/durable-55482f4f/script.sh: line 1: /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node: not found
Tests inside jenkins slave docker container
I tried executing the node version command directly in the jenkins slave docker container, however, output was same. Then I googled and referred the following thread which mentioned that this is because of the missing libraries needed by nodejs. Jenkins NodeJSPlugin node command not found
Following was the initial output on finding the shared libraries of nodejs from jenkins plugin
bash-4.4$ ldd /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node
/lib64/ld-linux-x86-64.so.2 (0x7fcbe2e7e000)
libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7fcbe2e7e000)
librt.so.1 => /lib64/ld-linux-x86-64.so.2 (0x7fcbe2e7e000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7fcbe2d29000)
libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fcbe2e7e000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7fcbe2d15000)
libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7fcbe2e7e000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fcbe2e7e000)
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node)
Error relocating /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node: gnu_get_libc_version: symbol not found
Error relocating /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node: __register_atfork: symbol not found
Error relocating /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node: setcontext: symbol not found
Error relocating /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node: makecontext: symbol not found
Error relocating /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node: backtrace: symbol not found
Error relocating /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node: getcontext: symbol not found
I then installed the missing libraries with the following command:
apk add libc6-compat gcompat
After installing the missing libraries, there was no error related to missing libraries, however there is still errors with "symbol not found" and node was still not executable.
bash-4.4# ldd /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node
/lib64/ld-linux-x86-64.so.2 (0x7f0e698f6000)
libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7f0e698f6000)
librt.so.1 => /lib64/ld-linux-x86-64.so.2 (0x7f0e698f6000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7f0e697a1000)
libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f0e698f6000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7f0e6978d000)
libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7f0e698f6000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f0e698f6000)
ld-linux-x86-64.so.2 => /lib/ld-linux-x86-64.so.2 (0x7f0e69787000)
Error relocating /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node: gnu_get_libc_version: symbol not found
Error relocating /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node: __register_atfork: symbol not found
Error relocating /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node: setcontext: symbol not found
Error relocating /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node: makecontext: symbol not found
Error relocating /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node: backtrace: symbol not found
Error relocating /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_10.19.0/bin/node: getcontext: symbol not found
bash-4.4#
I also checked the shared libraries of existing node v8, and it had no issues:
bash-4.4# which node
/usr/local/bin/node
bash-4.4# ldd /usr/local/bin/node
/lib/ld-musl-x86_64.so.1 (0x7f1e07118000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7f1e0539f000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7f1e0538b000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f1e07118000)
bash-4.4# /usr/local/bin/node -v
v8.11.3
So could anyone assist me on getting the Jenkins nodejs plugin to work?
回答1:
Using the Jenkins GUI you have installed the "mainstream" Linux NodeJS plugin. It is clear from the above outputs that this plugin is not Alpine Linux compatible.
Alpine Linux builds upon musl-libc - the musl standard C library, where as the majority of Linux distributions are built around glibc - GNU's standard C library. The libc library provides basic facilities to any native Linux program, including the standard C and POSIX APIs, and is an intrinsic part of the operating system. Therefore, binaries built on different operating systems with different libc implementations, such as Alpine's musl and Debian's glibc, usually don't mix, since the implementations are not fully compatible.
The missing libraries you mention, libc6-compat and gcompat, add a glibc compatibility layer around Alpine's musl, which allows for running simple glibc programs. However, it does not provide all glibc API's - hence the missing symbols.
For nodejs on Alpine, you should normally install the nodejs
package of the Alpine repository, but that unfortunately does not provide the Jenkins plugin. You would need a musl libc compatible nodeJS Jenkins plugin - and I'm not sure if one is available.
There are several options:
- You can go "full glibc" on Alpine Linux by installing proper glibc on your Alpine container (example). However, this will require restructuring of your current image, and you loose the "purity" of the Alpine image.
- If a musl compatible plugin is not to be found, consider switching to a (less) compact, glibc compatible base image, such as
debian
. - Or, try to build the Jenkins plugin from source on Alpine Linux, then install it manually.
来源:https://stackoverflow.com/questions/60539480/nodejs-with-jenkins-plugin-not-executable-in-alpine-image-and-displays-symbol-n