mibexsoftware / bamboo-plan-dsl-plugin

Configuration as code with a Groovy-based DSL or YAML for Atlassian Bamboo.
https://marketplace.atlassian.com/plugins/ch.mibex.bamboo.plandsl/
Other
40 stars 16 forks source link

Variable ${bamboo.buildNumber} substitutes to its value but it must not #85

Closed strakh-alex closed 6 years ago

strakh-alex commented 6 years ago

I'm trying to create a task which use variable ${bamboo.buildNumber} as a script argument. But this variable transforms to its value. And I can not find out a way to avoid this transformation. Tried to wrap up with $/ ,,, .$ but get an error: "No such property: bamboo for class: ch.mibex.bamboo.plandsl.dsl.jobs.Artifacts"

mrueegg commented 6 years ago

Hi,

Have you tried to use underscores instead to prevent substituting the variable with its value?

${bamboo_buildNumber}

You can find more information regarding this in our Wiki: https://github.com/mibexsoftware/bamboo-plan-dsl-plugin/wiki/FAQ#how-to-prevent-bamboo-variables-from-being-substituted

Hope this helps.

Best regards, Michael

strakh-alex commented 6 years ago

Hi. If I using ${bamboo_buildNumber} I get .${bamboo.BuildVersion}.${bamboo_buildNumber} in artifacts definition.

Code where I use this variable: artifacts { definition(name: """Project.${bamboo.BuildVersion}.${bamboo_buildNumber}""", copyPattern: 'Project.*.zip') { location '' shared true } }

strakh-alex commented 6 years ago

Found a way to escape variable using quotes " and slashes \: "Project.\${bamboo.BuildVersion}.\${bamboo.buildNumber}" But have another issue with escaping this variable into multiline string e.g.: script() { description '' inline { interpreter: ScriptInterpreter POWERSHELL scriptBody """ $packageName = Project.\${bamboo.BuildVersion}.\${bamboo.buildNumber}.zip try{ ... } catch { Throw ("ERROR: " + $error[0].Exception.Message) } """ } }

mrueegg commented 6 years ago

Hi,

What worked for me is to use single quotes in the multi-line string to prevent Bamboo from substituting the variables:

script() {
  description ''
  inline {
    interpreter: ScriptInterpreter POWERSHELL
    scriptBody '''
$packageName = Project.${bamboo.BuildVersion}.${bamboo.buildNumber}.zip
try{
} catch {
} '''
  }
}

Does that help you?

Best regards, Michael

strakh-alex commented 6 years ago

Hi. Yes, using 3 single quotes helps me. But symbols "\" and "$" should be escaped. Thank you!