Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

substring from variable in Bamboo script task

Hi everyone,

In Bamboo, I want a build to stop executing the following tasks based the last part of a variable. To be more specific: I only want to continue if the Maven version of the project I'm working on is a SNAPSHOT. I installed the Maven pom value extractor plugin, and now I have the project version, but how do I get the last part of that variable? I tried these:


#!/bin/bash
echo "========================================================"
echo Maven version is ${bamboo.maven.version}
echo Last 10 pos is ${bamboo.maven.version:(-10)}
echo ${bamboo.maven.version} | tail -c 10
echo "========================================================"


but they give these errors:

 

13-Nov-2018 12:44:17     ========================================================
13-Nov-2018 12:44:17     Maven version is 2.0.3-SNAPSHOT
13-Nov-2018 12:44:17     /opt/atlassian/bamboo/temp/DLWO-YLAN-BA-37-ScriptBuildTask-1970695706317157380.sh: line 5: ${bamboo.maven.version:(-10)}: bad substitution
13-Nov-2018 12:44:17     tail: cannot open `10' for reading: No such file or directory
13-Nov-2018 12:44:17     ========================================================

 

These commands work when run from a normal shell script. What can I do in a Bamboo script task to achieve this?

TIA,

Jules.

1 answer

1 accepted

0 votes
Answer accepted

Hi Jules,

Let me share a header we have in Bamboo on plan and global variables pages, which might explain why this is failing:

For task configuration fields, use the syntax ${bamboo.myvariablename}. Bamboo also supports nested variables. For instance, if you set variableName = world, and variable.value = Hello ${bamboo.variableName}, Bamboo will resolve it as Hello world. For inline scripts, variables are exposed as shell environment variables which can be accessed using the syntax $bamboo_MY_VARIABLE_NAME (Linux/Mac OS X) or %BAMBOO_MY_VARIABLE_NAME% (Windows).

Please try:

echo Last 10 pos is ${bamboo_maven_version:(-10)}
echo ${bamboo_maven_version} | tail -c 10

Thanks for pointing this out Daniel, it works now.

You are welcome! =]

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo 7.1 is here and is packed with value!

I'm happy to announce that Bamboo 7.1 has been released and it’s overflowing with awesome new features. Top-voted issues First and foremost, a bunch of JAC top voted issues has been delivered - y...

918 views 4 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you