在groovy中,Jenkins pipleline 在Slave中判断File exists

我的groovy 脚本在master 中如下,判断文件是否存在

============================================================

import com.xxxxx.Jenkins

import groovy.io.FileType

 

def call(def subProjectName,def path, def projectName) {

def result = false

File nf = new File("$path/$projectName/$subProjectName/plugins/")

if (nf.exists()) {

result = true

}

return result

}

运行结果正常,

但是当我在通过jenkins 把上边的代码在Slave中运行的时候,上边的代码总是取master 目录的文件,而不是取slave目录文件,所以把上边的代码改成如下

def call(def subProjectName,def path, def projectName) {

def result = false

def nf2 = fileExists("$path/$projectName/$subProjectName/plugins")

if (nf2) {

result = true

}

return result

}
结果正常取到了slave 的文件目录。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当将 Dockerfile 的内容写入 Jenkinsfile 时,可以使用 Jenkins 的 `docker.withRegistry` 和 `docker.build` 语法来构建和推送 Docker 镜像。 下面是一个示例的 Jenkinsfile,展示如何将 Dockerfile 内容写入其: ```groovy pipeline { agent any stages { stage('Build') { steps { script { // 定义镜像名称和标签 def imageName = 'my-docker-image' def imageTag = 'latest' // 使用 docker.withRegistry 语法指定 Docker 仓库的凭证 docker.withRegistry('https://your-docker-registry', 'docker-registry-credentials-id') { // 使用 docker.build 语法构建 Docker 镜像 def dockerImage = docker.build("${imageName}:${imageTag}", "-f - .", dockerfile: """ FROM ubuntu:latest # 这里写 Dockerfile 的内容 # ... """) // 推送镜像到 Docker 仓库 dockerImage.push() } } } } // 可以添加更多的阶段和步骤来部署镜像等 } } ``` 在上面的示例,我们使用 `docker.withRegistry` 语法指定了 Docker 仓库的 URL 和凭证,然后使用 `docker.build` 构建了 Docker 镜像。在 `docker.build` ,我们通过设置 `dockerfile` 参数,并将 Dockerfile 的内容作为多行字符串传递给它。 请根据实际情况替换示例的镜像名称、标签、Docker 仓库 URL 和凭证 ID。确保你已经在 Jenkins 配置了正确的 Docker 仓库凭证。 这样,当 Jenkins 运行该 Jenkinsfile 时,它将使用 Dockerfile 的内容构建 Docker 镜像,并将其推送到指定的 Docker 仓库

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值