Jenkins Pipeline 流水线 - 添加节点 使用代理

Jenkins 安装在 Windows 上
Docker 在Linux 上

流程

  • 将 Docker 在 Jenkins 节点中维护
  • Pipeline 中指定某些阶段使用哪个节点

添加节点

image
image
image
image
image

Checking Java version in the PATH
openjdk version "1.8.0_345"
OpenJDK Runtime Environment (build 1.8.0_345-b01)
OpenJDK 64-Bit Server VM (build 25.345-b01, mixed mode)
[11/01/22 15:47:11] [SSH] Checking java version of /opt/jenkins/jdk/bin/java
Couldn't figure out the Java version of /opt/jenkins/jdk/bin/java
bash: /opt/jenkins/jdk/bin/java: 娌℃湁閭d釜鏂囦欢鎴栫洰褰?

[11/01/22 15:47:11] [SSH] Checking java version of java
[11/01/22 15:47:11] [SSH] java -version returned 1.8.0_345.
[11/01/22 15:47:11] [SSH] Starting sftp client.
[11/01/22 15:47:12] [SSH] 正在拷贝最新版本的 remoting.jar...
Source agent hash is 8D575C4C8219E6AB2039295EC545C6C3. Installed agent hash is 8D575C4C8219E6AB2039295EC545C6C3
Verified agent jar. No update is necessary.
Expanded the channel window size to 4MB
[11/01/22 15:47:12] [SSH] Starting agent process: cd "/opt/jenkins" && java  -jar remoting.jar -workDir /opt/jenkins -jar-cache /opt/jenkins/remoting/jarCache
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)
Agent JVM has terminated. Exit code=1
[11/01/22 15:47:12] Launch failed - cleaning up connection
[11/01/22 15:47:12] [SSH] 连接关闭。

image
image
image

Pipeline 指定节点执行

pipeline {
    agent none
 
    stages { 
        stage('执行构建') {
            agent {	label 'DockerAgent-label' }  //这边使用节点名称或节点标签,都可以运行
            steps {
                sh 'docker --version' 
                echo '构建完成'
            }
        }
    }
}

image

posted @ 2022-11-01 17:34  VipSoft  阅读(1501)  评论(0编辑  收藏  举报