2

I'm trying to use bash variables in a shellScript in jetbrains space automation to no success.

My .space.kts is as follows;

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

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

in the above i'd expect "bar" to be echoed, but instead im getting the following error when this tries to run;

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

I had planned on parsing the branch name from JB_SPACE_GIT_BRANCH and storing it in a variable to use in a call to mvn to build and tag a container using Jib

Is there anyway that i can use variables within the content of a shellScript? or should/ can this be done in a different way?

Joffrey
  • 32,348
  • 6
  • 68
  • 100
BigMikeCodes
  • 23
  • 1
  • 5

1 Answers1

1

You need to replace $ by ${"$"}:

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

Or use a sh file file.sh like this:

FOO="bar"
echo $FOO

.

job("mvn compile") {
  container(displayName="mvn", image="maven:3.8.5-eclipse-temurin-17") {
      shellScript {
          content = """
              ./file.sh
          """
      }
  }
}
Lucas Bodin
  • 311
  • 3
  • 19
  • Single quotes are also possible within the {} – alexander Sep 12 '22 at 17:08
  • If you just want to reference an external script file, you can use the `location` property (with a path) instead of `content`, so there is no intermediate generated script file – Joffrey Feb 22 '23 at 12:28