詹金斯:从詹金斯管道执行脚本 [英] Jenkins: Execute a script from jenkins pipeline

查看:38
本文介绍了詹金斯:从詹金斯管道执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个构建 java 工件的 jenkins 管道,将其复制到目录,然后尝试执行外部脚本.

I have a jenkins pipeline that builds a java artifact, copies it to a directory and then attempts to execute a external script.

我在管道脚本中使用此语法来执行外部脚本

I am using this syntax within the pipeline script to execute the external script

dir('/opt/script-directory') {
    sh './run.sh'
}

脚本只是一个简单的docker build脚本,但是build会失败除了这个例外:

The script is just a simple docker build script, but the build will fail with this exception:

java.io.IOException: Failed to mkdirs: /opt/script-directory@tmp/durable-ae56483c

该错误令人困惑,因为该脚本没有创建任何目录.它只是构建一个 docker 映像并将新构建的 java 工件放置在该映像中.

The error is confusing because the script does not create any directories. It is just building a docker image and placing the freshly built java artifact in that image.

如果我在 jenkins 中创建一个执行外部脚本的不同作业它是唯一的构建步骤,然后使用以下语法从我的管道脚本中调用该作业:

If I create a different job in jenkins that executes the external script as its only build step and then call that job from my pipeline script using this syntax:

build 'docker test build'

一切正常,脚本在其他作业和管道中执行按预期继续.

everything works fine, the script executes within the other job and the pipeline continues as expected.

这是执行工作区外部脚本的唯一方法吗?

Is this the only way to execute a script that is external to the workspace?

我尝试从内部执行脚本时做错了什么管道脚本?

What am I doing wrong with my attempt at executing the script from within the pipeline script?

推荐答案

问题是 jenkins 用户(或运行 Jenkins 从属进程的任何用户)没有 /opt 的写权限sh 步骤想要在那里创建 script-directory@tmp/durable-ae56483c 子目录.

The issue is that the jenkins user (or whatever the user is that runs the Jenkins slave process) does not have write permission on /opt and the sh step wants to create the script-directory@tmp/durable-ae56483c sub-directory there.

要么删除 dir 块并使用脚本的绝对路径:

Either remove the dir block and use the absolute path to the script:

sh '/opt/script-directory/run.sh'

或授予 jenkins 用户对文件夹 /opt 的写入权限(出于安全原因不推荐)

or give write permission to jenkins user to folder /opt (not preferred for security reasons)

这篇关于詹金斯:从詹金斯管道执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆