I have a command that I want to use to deploy my build using salt but Bitbucket pipelines doesn't like the command.
ssh -i ~/.ssh/myKey.pem ec2-user@<ServerIP> sudo salt --async -C "G@ec2_tags:Environment:Production and G@ec2_tags:Project:myproject" state.sls deploy "pillar={ 'project': 'myproject', 'buildNumber': $BITBUCKET_BUILD_NUMBER }"
The command SSH's onto my Salt Master, targets minions using a compound search and and runs a state file to deploy the project that is passed in the pillar.
Two things that pipelines doesn't like are the compound search and the JSON structure in the pillar. Pipelines doesn't like the colons because it messes with the YAML structure. I was able to solve the pillar problem by removing the spaces but I can't solve the problem with the compound search. It seems to be splitting the compound search up and salt complains with the error:
Executing run on ['i-0f19d29793f453621']
i-0f19d29793f453621:
'and' is not available.
I have managed to get it working by setting Bitbucket environment variables to the values of the compound search and the pillar but that really reduces my flexibility in being able to use the $BITBUCKET_BUILD_NUMBER.
I've spent about a day on this so far but I can't see a solution with the route I am currently going down and I just wanted to see if anyone else had any suggestions for me to try before I start trying to solve this problem a different way.
Update:
Just after posting this I found a way of getting close to the perfect solution. I wanted the pipeline code to be human readable as much as possible and not to reference variables stored in Bitbucket, so what I managed to get working was the following steps in my pipeline where I export a couple of variables and then use the variables in the salt command. I think the "and" error I was getting previously must be caused by something happening to the quotes around the compound search when it gets processed by bitbucket.
- export saltmatch='"G@ec2_tags:Environment:Production and G@ec2_tags:Project:myproject"'
- export pillar="\"pillar={'project':'myproject','buildNumber',$BITBUCKET_BUILD_NUMBER}\""
- ssh -i ~/.ssh/myKey.pem ec2-user@<ServerIP> sudo salt --async -C $saltmatch state.sls deploy $pillar