我有一个简单的Jenkins管道,它创建了一个包含3个容器的pod——jnlp、dind和示例测试
如下所示-
agent {
kubernetes {
yaml """
apiVersion: v1
kind: Pod
metadata:
name: example-pb
annotations:
container.apparmor.security.beta.kubernetes.io/dind: unconfined
container.seccomp.security.alpha.kubernetes.io/dind: unconfined
labels:
some-label: label1
spec:
serviceAccountName: example
securityContext:
runAsUser: 10000
runAsGroup: 10000
containers:
- name: jnlp
image: 'jenkins/jnlp-slave:4.3-4-alpine'
args: ['\$(JENKINS_SECRET)', '\$(JENKINS_NAME)']
- name: dind
image: docker:dind
securityContext:
runAsUser: 0
runAsGroup: 0
fsGroup: 0
privileged: true
tty: true
volumeMounts:
- name: var-run
mountPath: /var/run
- name: example-test
image: pranavbhatia/example-test:0.1
securityContext:
runAsUser: 0
runAsGroup: 0
fsGroup: 0
volumeMounts:
- name: var-run
mountPath: /var/run
volumes:
- emptyDir: {}
name: var-run
"""
}
}
还定义了几个阶段-
stages {
stage ('DIND') {
steps {
container('dind') {
sh 'pwd && echo "Pulling image" && docker pull ubuntu:18.04'
}
}
}
stage ('EXAMPLE') {
steps {
container('example-test') {
sh './example'
}
}
}
现在我的根文件夹中有了这个脚本“示例”,我想运行它,但不知怎么的,它找不到。
Dockerfile看起来像这样-
FROM ubuntu:18.04
COPY ./example ./example
#make it executable
RUN chmod +x ./example
#command to keep container running in detached mode
CMD tail -f /dev/null
pwd返回“/home/jenkins/agent/workspace/test pipeline”,而不是docker容器路径。
结果如下-
Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] podTemplate
[Pipeline] {
[Pipeline] node
Created Pod: test-pipeline-14-s7167-4zcg5-s68gw in namespace dc-pipeline
Still waiting to schedule task
‘test-pipeline-14-s7167-4zcg5-s68gw’ is offline
Agent test-pipeline-14-s7167-4zcg5-s68gw is provisioned from template test-pipeline_14-s7167-4zcg5
---
apiVersion: "v1"
kind: "Pod"
metadata:
annotations:
container.apparmor.security.beta.kubernetes.io/dind: "unconfined"
container.seccomp.security.alpha.kubernetes.io/dind: "unconfined"
buildUrl: "http://jenkins-164-229:8080/job/test-pipeline/14/"
runUrl: "job/test-pipeline/14/"
labels:
some-label: "label1"
jenkins: "slave"
jenkins/label: "test-pipeline_14-s7167"
name: "test-pipeline-14-s7167-4zcg5-s68gw"
spec:
containers:
- args:
- "$(JENKINS_SECRET)"
- "$(JENKINS_NAME)"
env:
- name: "JENKINS_SECRET"
value: "********"
- name: "JENKINS_TUNNEL"
value: "jenkins-164-229-agent:50000"
- name: "JENKINS_AGENT_NAME"
value: "test-pipeline-14-s7167-4zcg5-s68gw"
- name: "JENKINS_NAME"
value: "test-pipeline-14-s7167-4zcg5-s68gw"
- name: "JENKINS_AGENT_WORKDIR"
value: "/home/jenkins/agent"
- name: "JENKINS_URL"
value: "http://jenkins-164-229:8080/"
- name: "HOME"
value: "/home/jenkins"
image: "jenkins/jnlp-slave:4.3-4-alpine"
name: "jnlp"
volumeMounts:
- mountPath: "/home/jenkins/agent"
name: "workspace-volume"
readOnly: false
- image: "pranavbhatia/example-test:0.1"
name: "example-test"
securityContext:
runAsGroup: 0
runAsUser: 0
volumeMounts:
- mountPath: "/var/run"
name: "var-run"
- mountPath: "/home/jenkins/agent"
name: "workspace-volume"
readOnly: false
- image: "docker:dind"
name: "dind"
securityContext:
privileged: true
runAsGroup: 0
runAsUser: 0
tty: true
volumeMounts:
- mountPath: "/var/run"
name: "var-run"
- mountPath: "/home/jenkins/agent"
name: "workspace-volume"
readOnly: false
nodeSelector:
beta.kubernetes.io/os: "linux"
restartPolicy: "Never"
securityContext:
runAsGroup: 10000
runAsUser: 10000
serviceAccountName: "example"
volumes:
- emptyDir: {}
name: "var-run"
- emptyDir:
medium: ""
name: "workspace-volume"
Running on test-pipeline-14-s7167-4zcg5-s68gw in /home/jenkins/agent/workspace/test-pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (DIND)
[Pipeline] container
[Pipeline] {
[Pipeline] sh
+ pwd
/home/jenkins/agent/workspace/test-pipeline
+ echo 'Pulling image'
Pulling image
+ docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
7595c8c21622: Pulling fs layer
d13af8ca898f: Pulling fs layer
70799171ddba: Pulling fs layer
b6c12202c5ef: Pulling fs layer
b6c12202c5ef: Waiting
d13af8ca898f: Verifying Checksum
d13af8ca898f: Download complete
70799171ddba: Verifying Checksum
70799171ddba: Download complete
b6c12202c5ef: Verifying Checksum
b6c12202c5ef: Download complete
7595c8c21622: Verifying Checksum
7595c8c21622: Download complete
7595c8c21622: Pull complete
d13af8ca898f: Pull complete
70799171ddba: Pull complete
b6c12202c5ef: Pull complete
Digest: sha256:a61728f6128fb4a7a20efaa7597607ed6e69973ee9b9123e3b4fd28b7bba100b
Status: Downloaded newer image for ubuntu:18.04
docker.io/library/ubuntu:18.04
[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (EXAMPLE)
[Pipeline] container
[Pipeline] {
[Pipeline] sh
+ pwd
/home/jenkins/agent/workspace/test-pipeline
+ ./example
/home/jenkins/agent/workspace/test-pipeline@tmp/durable-26584660/script.sh: 1: /home/jenkins/agent/workspace/test-pipeline@tmp/durable-26584660/script.sh: ./example: not found
[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
你知道怎么解决这个问题吗?
用sh'/example'(不带点)执行可能会有用。您将其安装在根文件系统中,但当容器中的命令从Jenkins运行时,PWD将成为工作区。
问题内容: 我已经尝试过将docker和jenkins一起使用,两者都安装在我的机器上(w10),并且我使用jankins运行docker镜像。但是,当我按照jenkins文档中的示例(来自doc的示例)时,它不起作用。不涉及时,不同的管道脚本可以工作,我还尝试从jenkins config接口添加。 管道脚本 错误堆栈 我在SO上发现了类似的问题\(相同但没有明确的解决方案) 问题答案: 您的工
最近,我的工作场所一直在从CircleCI过渡到Azure管道,因此我们一直在迁移我们所有的CI。虽然大多数人都有些直截了当,但这种特殊的管道需要在docker映像中运行我们的linux作业。以下是CircleCI中的内容: 这是它目前在Azure管道中的样子: 在最后一个脚本期间,任何尝试运行没有“apt-get”行的脚本都会失败,从而产生错误:退出代码:ENOENT。spawn icns2pn
问题内容: 请注意: 这个问题是基于旧的,现在称为“脚本化”管道格式的。使用“声明性管道”时,可以将并行块嵌套在阶段块内部(请参阅带有声明性管道1.2的并行阶段)。 我想知道Jenkins工作流/管道插件,特别是并行步骤应该如何工作。如何将它们与构建阶段混合使用。我了解一般模式: 但是,我想并行运行几个阶段(在具有多个执行程序的同一节点上),因此我尝试添加以下阶段: 这不能按预期方式工作。“执行任
问题内容: 我正在尝试在Jenkins脚本化管道中运行条件步骤,但是我不确定如何仅在上一步成功的情况下运行步骤。例如,在以下情况中,如果“测试”阶段成功,我只想运行“推送工件”阶段: 我知道声明性管道允许您使用“后”条件,但是我对Jenkins中的声明性管道与脚本化管道的理解是,脚本化管道提供了更大的灵活性。有没有一种方法可以基于脚本管道中其他阶段的成功来运行阶段? 问题答案: 在詹金斯管道中没有
问题内容: 在groovy脚本中(用于jenkins管道):如何运行命令而不是命令? 我尝试了以下方法: 在通话中致电“ ” : 将呼叫替换为呼叫: 附加信息: 我的命令比命令更复杂。 问题答案: 您提供的Groovy脚本正在将结果脚本中的第一行格式化为空白行。shebang告诉脚本使用/ bin / bash而不是/ bin / sh运行,它需要位于文件的第一行,否则它将被忽略。 因此,您应该这
我正在编写一个Groovy脚本,其中包含部署terraform的作业。我正在使用作业DSL并使种子作业由JCasC实现,一切正常。然后我有一个包含作业的Groovy文件的存储库。 如果我将Groovy文件保持为单个作业,它就可以正常工作。 然而,我希望能够构建具有构建阶段的管道。我知道我可以把管道写在詹金斯文件中 我有这个作为开始: 但是,我看到了这个错误: 我已经尝试了各种方法,并阅读了一堆文档