栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Jenkins声明式管道,在从属代理上运行groovy脚本

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Jenkins声明式管道,在从属代理上运行groovy脚本

原来,Groovy
File命令被认为是不安全的,尽管它们将在主服务器上运行,但不会在从属服务器上运行。如果您从将代理设置为另一个节点的脚本中调用它们,它将仍然可以在主节点上而不是在代理上执行命令。这是文章发布的摘录https://support.cloudbees.com/hc/en-
us/articles/230922508-Pipeline-Files-
manipulation


File类的操作在master上运行,因此仅当build在master上运行时才起作用,在此示例中,我创建了一个文件,并检查是否可以在存在方法的节点上访问它,该文件不存在,因为

newFile(file)
在主机,要对此进行检查,我将搜索
Users
主机上存在但节点中不存在的文件夹。

stage 'file move wrong way'  //it only works on master  node('slave') {    def ws = pwd()    def context  = ws + "/testArtifact"    def file = ws + '/file'    sh 'touch ' + file    sh 'ls ' + ws    echo 'File on node : ' + new File(file).exists()    echo 'Users : ' + new File('/Users').exists()    sh 'mv ' + file + ' ' + context    sh 'ls ' + ws  }

要执行文件操作命令,我们建议使用本机命令。

这是shell中操作的简单示例

stage 'Create file'  sh 'touch test.txt'stage 'download file'  def out='$(pwd)/download/maven.tgz'  sh 'mkdir -p ./download'  sh 'curl -L http://ftp.cixug.es/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz -o ' + outstage 'move/rename'  def newName = 'mvn.tgz'  sh 'mkdir -p $(pwd)/other'  sh 'mv ' + out + ' ' + newName  sh 'cp ' + newName + ' ' + out}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/649892.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号