在Azure Devops中配置Yaml以在Mac上运行Groovy脚本 [英] Configure yaml in azure devops to run groovy script on Mac

查看:105
本文介绍了在Azure Devops中配置Yaml以在Mac上运行Groovy脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前使用JenkinsFile在jenkins中运行CI/CD管道,但是现在我们正在迁移到Azure DevOps.因此,要在Mac上的Azure DevOps中建立管道,我使用的是Yaml文件.

Earlier I was using JenkinsFile to run CI/CD pipeline in jenkins, but now we're migrating to Azure DevOps. So to build a pipeline in Azure DevOps on Mac, I'm using a Yaml file.

在jenkinsfile中,我使用以下语法运行了groovy脚本:

In jenkinsfile, I ran groovy script using the following syntax:

pipe = load ('path/to/groovy/script')
pipe.go()

,其中"go()"是groovy脚本中的函数

,where "go()" is a function in the groovy script

但是,我无法以类似方式配置yaml文件

But, I'm unable to configure the yaml file in similar way

我在网上发现的是通过gradle build来运行此groovy

What I found online was running this groovy via gradle build

我想配置yaml以像在jenkinsfile中一样运行groovy脚本,而不安装gradle或任何第三方.

I want to configure the yaml to run groovy script like in jenkinsfile, as in, without installing gradle or any third party.

推荐答案

在azure devops中配置yaml以运行groovy脚本

Configure yaml in azure devops to run groovy script

如果使用私有代理,则必须在代理计算机上安装:

If you are using private agent, you have to install on the agent machine:

  • Java 8 JDK
  • Apache Groovy 2.5.7(以zip下载并提取到一些本地 文件夹)
  • Java 8 JDK
  • Apache Groovy 2.5.7 (Downloaded as zip and extracted to some local folder)

然后设置环境变量,打开CMD并运行以下命令:

Then set environment variables, open CMD and run these commands:

setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_101"
setx /M PATH "%PATH%;C:\Program Files\Java\jdk1.8.0_101\bin"
setx GROOVY_HOME "C:\Users\<UserName>\Desktop\apache-groovy-sdk-2.5.7" (the first path is when you extracted the Apache Groovy 2.5.7)
setx /M PATH "%PATH%;C:\Users\<UserName>\Desktop\apache-groovy-sdk-2.5.7\bin" (the first path is when you extracted the Apache Groovy 2.5.7 )

现在,我们可以在构建期间运行groovy脚本而无需安装gradle或任何第三方,在构建定义中添加 Command Line Task (不是Bash)并选择您的groovy脚本:

Now, we could run groovy scripts without installing gradle or any third party during the building, in the build definition add Command Line Task (not Bash) and choose your groovy script:

如果使用托管代理,则需要更多步骤来下载和解压缩Apache Groovy 2.5.7任务.

If you are using the hosted agent, you need more steps to download and unzip task Apache Groovy 2.5.7.

希望这会有所帮助.

这篇关于在Azure Devops中配置Yaml以在Mac上运行Groovy脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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