I am new to Bamboo Atlassian environment. I have a question regarding implement Bash script under plan/branch on Bamboo.
I am trying to run a regex inside script stage but I am getting an error:
/tmp/SW-2636-ScriptBuildTask-4921335221935380637.sh: [[: not found
My code:
if [[ ${bamboo.planRepository.branchName} =~ [0-9]+\.[0-9]+R ]]; then
do Blah Blah
else
do something else
fi
I have also tried with singe [] instead of [[ ]] but didn't get.
I ran this script independently as a Bash script and its running fine. Unable to understand how to add regex inside if condition over Bamboo.
Any suggestion/example would be helpful
This will make a trick:
if [ "$(ps -p "$$" -o comm=)" != "bash" ]; then
bash "$0" "$#"
exit "$?"
fi
Add this script at the top of your script to make Bamboo Bash compatible.
Related
I am looking for a reliable method for generating and using temporary, disposable folders, as part of tox environment creation.
[testenv:var-test]
description = Try to store output of a shell command
tmpdir = mktemp -d
commands =
echo {[testenv:var-test]tmpdir}
# prints "mktemp -d" (command is not run)
tmpdir = mktemp -d
# ERROR: InvocationError for command could not find executable tmpdir
There may be better ways, but you certainly can call a bash script from within the commands section.
tox.ini
[testenv]
whitelist_externals = bash
commands =
bash {toxinidir}/commands.sh
commands.sh
TEMP=`mktemp -d`
echo $TEMP
output of a tox run
❯ tox
python run-test-pre: PYTHONHASHSEED='562823002'
python run-test: commands[0] | bash /home/jugmac00/stackOverflow/commands.sh
/tmp/tmp.snc2T0Fa6W
_________________________________________________________ summary __________________________________________________________
python: commands succeeded
congratulations :)
I am trying to put together a simple script that does a regex on a git clone output and captions the directory that the default clone cmd is cloning too and then captures this into a shell for or something that can then be piped into xargs?
E.g:
git clone git#github.com:thorchain/instaswap-sdk.git |& grep "\'\S*\'" | xargs cd
In this example grep is not the right tool as its output is the matching line and not the match. However, for the life of me, I can't seem to find a simple regex matching tool?
Thanks in adv
Luke
Turns out the missing bit was the grep -o that I needed. What I was trying to do was built a bash function the git cloned and cd into the repos directory.
End solution here:
function gitc() {
cd `git clone "$#" |& grep -o "\'\S*\'" | tr -d "'"`
}
I have tried this regex in centos
RegEx: echo 'select-value'|sed -r 's/(-)(\w)/\U\2/g'
Output: selectValue
But in alpine i am not getting the output when i tried the below regex
RegEx: echo 'select-value'|sed -r 's/(-)(\w)/\%U\2/g'
Output: select%Uvalue
Expected Output: selectValue
Please suggest the right regex.
Thanks
It seems that alpine uses the busybox sed by default. You have to install the gnu sed (it may be already installed).
In a docker alpine 3.5 container I've tried that one and it worked echo 'select-value'|/bin/sed -r 's/(-)(\w)/\U\2/g'. Mind the /bin/sed part. Gnu sed was already installed in the docker image.
If you have not luck with that you may use awk if available:
echo 'select-value-another-value'|awk -F'-' '{ for(i=1; i<=NF; i++) printf toupper(substr($i,1,1)) substr($i,2);printf "\n"}'
If you don't have to use sed, try perl:
$ echo 'select-value-but-not-that-one'|perl -pe 's/-(\w)/\u$1/g'
selectValueButNotThatOne
Supposing my lein project is located in /some/location/project and my current location is /another/location/ how can I run lein build without changing to project location cd /some/location/project?
For example, in maven
mvn -f /path/to/pom.xml
As far as I can tell lein doesn't have an option like this. You have to be in the directory. (Perhaps someone else will correct me.) However, you could write a shell script that does what you want. For example, in a unix that provides the getopts utility, you could use the following script, which might be called "leinthere":
#!/bin/sh
if getopts f: option; then
# user supplied -f
if [ -d "$OPTARG" ]; then
# user also supplied name of a real dir, now in $OPTARG
cd "$OPTARG"
shift 2 # get rid of -f and the dir name
else
# user supplied -f, but not a real dir name
echo "usage: $0 [-f project-dir] [lein args]"
exit 1
fi
fi
# now just run lein in the normal way:
lein "$#"
All
I have following shell command working as per expectation on shell but not working when invoked inside perl
Shell command:
grep -P -s -irl --include \*.v "\s+hello\s?[(].*" <PATH>
working fine
Inside Perl:
$inst_search = `grep -P -s -irl --include \*.v "\s+$inst\s?[(].*" #plt_dirs`;
not working
I am suspecting i am missing something with regexp inside grep..please correct me !
Thanks,
Vivek
Perl will escape special shell characters when calling exec/system/qx (or backticks) with a string.
Try using the exec or system functions, but passing a list, e.g.
system('grep', '-P', '-s', '-irl', '--include', '\*.v', '"\s+hello\s?[(].*"', #plt_dirs);
You may also want to look at a module that does some of the error handling for you, like IPC::System::Simple.
Try this one:
$inst_search = qx#grep -P -s -irl --include \*.v "\s+$inst\s?[(].*" #plt_dirs#;
Or use any other non-alphanumeric character instead of "#"for quoting.