Jetbrains Space shellScript 变量

Jetbrains Space shellScript variables

我试图在 jetbrains space 自动化的 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 的内容中使用变量?或者应该/可以用不同的方式完成吗?

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

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
          """
      }
  }
}