#jenkins
#kubernetes
#pipeline
流水线卡在sh那里不动了,执行不了sh里面的命令,但是我通过终端进去容器内部执行都一切正常,是哪里出问题了,麻烦帮我看看
pipeline {
agent {
kubernetes {
// 定义一个Pod模板
yaml """
apiVersion: v1
kind: Pod
spec:
serviceAccountName: jenkins-qygoydxwa9a
containers:
- name: jnlp
image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/jenkins/inbound-agent:3309.v27b_9314fd1a_4-7
tty: true
env:
- name: JENKINS_URL
value: http://jenkins-qygoydxwa9a.jenkins.svc.cluster.local:8080/
- name: kubectl
image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/bitnami/kubectl:1.33.1
command:
- cat
tty: true
"""
}
}
stages {
stage('部署到 Kubernetes') {
steps {
container('kubectl') {
// 2. 使用 withKubeConfig 并传入正确的凭据ID字符串
withKubeConfig(credentialsId: 'kubeconfig') {
sh 'kubectl version --client'
sh 'echo "--- Listing pods in all namespaces ---"'
sh 'kubectl get pods -A'
}
}
}
}
}
}
Running on test-k8s-2-j2d12-zb3mw-vnjh3 in /home/jenkins/agent/workspace/test-k8s
[Pipeline] {
[Pipeline] stage
[Pipeline] { (部署到 Kubernetes)
[Pipeline] container
[Pipeline] {
[Pipeline] withKubeConfig
[kubernetes-cli] creating missing workspace to write temporary kubeconfig
[Pipeline] {
[Pipeline] sh
process apparently never started in /home/jenkins/agent/workspace/test-k8s@tmp/durable-bd126789
(running Jenkins temporarily with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true might make the problem clearer)
[Pipeline] }
[kubernetes-cli] kubectl configuration cleaned up
[Pipeline] // withKubeConfig
[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
Agent test-k8s-2-j2d12-zb3mw-vnjh3 was deleted, but do not have a node body to cancel
[Pipeline] // node
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
ERROR: script returned exit code -2
Finished: FAILURE

