Shell脚本无法读取Groovy变量,尝试了多种方法

发布于 2025-01-24 20:26:49 字数 1862 浏览 2 评论 0原文

我是Shell和Groovy的新手,并且我已经在下面搜索并阅读了解决方案,但似乎都没有工作

Groovy参数到Shell脚本 通过Groovy变量到Shell Script 读取文件到变量shell脚本 詹金斯 如何将Groovy Variable传递给Jenkinsfile中的shold script /a>

问题: 我想从Groovy变量中读取价值并将其传递给Shell脚本,但是我要么获得空白值,

要么以下文字变量名称是我的代码:

        def Tenant_Instances = ''
       //some more declarations and code
          if(tenant_created)
            {
  Tenant_Instances = "author.${ciTenant}.rally-dev.com,publish.${ciTenant}.rally-dev.com"
       println("tenant instance are -"+Tenant_Instances) //value coming fine here
                //some code here
           println("tenant instance again are -"+Tenant_Instances) //values coming fine here too
                  
                         sh '''#!/bin/bash
                                echo "[MNR] - Beginning deployment of bundle(s) to AEM Package Manager"
                                
                                IFS="," read -ra INSTANCES <<< $Tenant_Instances
                                echo "demo ${INSTANCES}" -->here value does not come properly

我尝试用'tenant_instances'替换tenant_instances'或“ $ {tenant_instances}”或$ {tenant_instances}”或“ $ tenant_instances” ...但似乎都没有用。

I am new to shell and groovy and I have already googled and read solutions below, but none of it seems to be working

Groovy parameter to shell script
Pass groovy variable to shell script
read file to variable shell script
How to pass a groovy variable to a shell block jenkins
How to pass groovy variable to shell script in Jenkinsfile?

Issue:
I want to read value from the groovy variable and pass it to shell script but either I get blank value or the literal variable name

Below is my code:

        def Tenant_Instances = ''
       //some more declarations and code
          if(tenant_created)
            {
  Tenant_Instances = "author.${ciTenant}.rally-dev.com,publish.${ciTenant}.rally-dev.com"
       println("tenant instance are -"+Tenant_Instances) //value coming fine here
                //some code here
           println("tenant instance again are -"+Tenant_Instances) //values coming fine here too
                  
                         sh '''#!/bin/bash
                                echo "[MNR] - Beginning deployment of bundle(s) to AEM Package Manager"
                                
                                IFS="," read -ra INSTANCES <<< $Tenant_Instances
                                echo "demo ${INSTANCES}" -->here value does not come properly

I have tried replacing Tenant_Instances with 'Tenant_Instances' or "${Tenant_Instances}" or $Tenant_Instances or '$Tenant_Instances'... but none of it seem to work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文