【问题标题】:Jetbrains Space shellScript variablesJetbrains Space shellScript 变量
【发布时间】:2023-02-01 18:24:07
【问题描述】:

我试图在 jetbrains 空间自动化中的 shellScript 中使用 bash 变量但没有成功。

我的 .space.kts 如下;

job("mvn compile"){
    container(displayName="mvn", image="maven:3.8.5-eclipse-temurin-17"){

        shellScript {
            content = """
                FOO="bar"
                echo $FOO
            """
        }
    }
}

在上面我期望“bar”被回显,但是当它试图运行时我得到了以下错误;

Dsl file '/tmp/16487320722162400386/.space.kts' downloaded in 1736 ms
Compiling DSL script /tmp/16487320722162400386/.space.kts...
downloading /home/pipelines-config-dsl-compile-container/space-automation-runtime.jar ...
    [SUCCESSFUL ] com.jetbrains#space-automation-runtime;1.1.100932!space-automation-runtime.jar (71ms)
Compilation failed in 8.652797664s.
ERROR Unresolved reference: FOO (.space.kts:9:23)
Cleaned up the output folder: /tmp/16487320722162400386
DSL processing failed: Compilation exited with non zero exit code: 2. Exit code: 102

我曾计划从 JB_SPACE_GIT_BRANCH 解析分支名称并将其存储在一个变量中以用于调用 mvn 以使用 Jib 构建和标记容器

无论如何,我可以在 shellScript 的内容中使用变量吗?或者应该/可以以不同的方式完成吗?

【问题讨论】:

    标签: jetbrains-space-automation jetbrains-space


    【解决方案1】:

    您需要将 $ 替换为 ${"$"}:

    job("mvn compile") {
      container(displayName="mvn", image="maven:3.8.5-eclipse-temurin-17") {
          shellScript {
              content = """
                  FOO="bar"
                  echo ${"$"}FOO
              """
          }
      }
    }
    

    或者像这样使用 sh 文件 file.sh:

    FOO="bar"
    echo $FOO
    

    .

    job("mvn compile") {
      container(displayName="mvn", image="maven:3.8.5-eclipse-temurin-17") {
          shellScript {
              content = """
                  ./file.sh
              """
          }
      }
    }
    

    【讨论】:

    • {} 中也可以使用单引号
    猜你喜欢
    • 2013-02-04
    • 1970-01-01
    • 2010-12-21
    • 1970-01-01
    • 2017-05-25
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多