(mods, sorry for resposting, I posted in the previous thread, but I don't know if that makes it go up in the threads list, remove if needed)
Hello,
I have a pipeline that takes a SQL script and invokes it into a database via powershell.
I have a variable "database", which is "value1" for the main branch (master) and "value2" which I have overridden for branch "development.
The problem I am having: when running development branch build I can see in logs that Bamboo substitutes the database variable for the one set in master branch. What I mean is, it takes "value1", but not "value2". Does anybody have an idea where the problem might be?
Log:
Hello Jonas,
Welcome to Atlassian community.
Can you do two test and let me know the output
Test 1 :
1) For the plan create a new script task and put it at the top and print the value for below and let me know what values it prints? echo ${bamboo.database}
2) Can you add one more task"Dump Variable to log"
Run both the master as well as branch and confirm what is the value of variable in both the cases.
Regards,
Shashank kumar
Hello Kumar,
I solved it immediately after posting (always happens...).
I didn't realise it at first, but this solution works only for default branches (in my case development and master).
What I didn't notice is that it doesn't work when making pull requests.
Since Bamboo creates a new branch for each new pull request, that new branch does not have any default variable values, so it takes the values from the default repository branch, which in this case is master, and default database variable value is "eurokasa".
A little powershell hacking did the trick, but it would be nice to have a better in-house solution.
My solution: check if pull request key exists, if yes - check target branch and set database variable accordingly.
If not - use default branch variable.
$database = ""
write-host "Default database is ${bamboo.database}"
if ("${bamboo.repository.pr.key}" -ne "") {
write-host "Pull request is being made, target branch is ${bamboo.repository.pr.targetBranch}"
$database = if ("${bamboo.repository.pr.targetBranch}" -eq "development") { "eurokasa_dev" } else { "eurokasa" }
write-host "Substituting default database to $($database)"
} else {
$database = "${bamboo.database}"
write-host "Using default database"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Jonas good to know that it's working!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.