How to pass params between job steps?

I need to get current project version from pom.xml on build stage, and pass it to dockePush stage

in docs was found this:

Sometimes it is enough to pass a string from one Automation step to another, for example, an access token, command-line arguments, and so on. In this case, you can use sharing of parameters .

but have no page where it should be described

help me plz

was try like this:

var projectGroupId = "__projectGroupId"
var projectArtefactId = "__projectArtefactId"
var projectVersion = "__projectVersion"

host {
kotlinScript {
val pom = File("pom.xml")
val mapper = XmlMapper()
val pomObject = mapper.readTree(pom)

projectGroupId = pomObject["groupId"].asText()
projectArtefactId = pomObject["artifactId"].asText()
projectVersion = pomObject["version"].asText()

println("$projectGroupId.$projectArtefactId-$projectVersion") // HERE IS VALUES FROM POM.XML
}
}

container(displayName = "Deploy maven package", image = "maven:3-openjdk-11-slim") {
shellScript {

// BUT HERE IS DEFAULT VALUES
content = """
echo $projectGroupId
echo $projectArtefactId
echo $projectVersion
""".trimIndent()
}
}

 

1
2 comments

Hello,

Right now, there is no elegant way to do that, but the approach of using a file share should do the trick. Here is the related documentation with an example https://www.jetbrains.com/help/space/sharing-execution-context.html#accessing-file-share-directly

Another option is to enable the related feature flag for your Space organization since we have a new and much more simple mechanism under internal testing. Although it is pretty stable, anyway, it is always some risk in the early stages. So please let me know if you would like to try this new feature (in this case, I will need to know the name of your Space organization). It will allow you to write your code in the following way: 


host {
    kotlinScript { api ->
        val pom = File("pom.xml")
        val mapper = XmlMapper()
        val pomObject = mapper.readTree(pom)

        projectGroupId = pomObject["groupId"].asText()
        projectArtefactId = pomObject["artifactId"].asText()
        projectVersion = pomObject["version"].asText()

        api.parameters["projectGroupId"] = projectGroupId
        api.parameters["projectArtefactId"] = projectArtefactId
        api.parameters["projectVersion"] = projectVersion
    }
}

container(displayName = "Deploy maven package", image = "maven:3-openjdk-11-slim") {
    shellScript {
        content = """
            echo {{ projectGroupId }}
            echo {{ projectArtefactId }}
            echo {{ projectVersion }}
        """.trimIndent()
    }
}

Looking forward to hearing from you soon!

1

That's really what i need! Plz turn on it's for me. How i can provide my Space org sensitively?

And its will be super cool, if u add this "last lambda parameter API" with ```api.parameters``` feature (and all other API features), after extension lambda of builder - everywhere. Such as it realized in ```kotlinScript```.

I mean something like this:

host {
shellScript {
content = "export SUPER_USEFUL_PARAM=value"
}
dockerBuildPush {
// MAYBE HERE IT WILL BE USEFUL TOO
it.parameters["paramForNextStage"] = this.labels
tags {
// I SHOULD PASS PROJECT PARAMS HERE FINALLY, BUT HERE ONLY JB_ENV, \$SUPER_USEFUL_PARAM IS EMPTY HERE
+"${it.parameters["projectGroupId"]}.${it.parameters["projectArtefactId"]}-${it.parameters["projectVersion"]}"
}
}
}

In general, i need a possibility to have common context, for all pipeline, and pass params form/to shellScript and other strings

 

0

Please sign in to leave a comment.