0

I'm using Bamboo for Continous Deployment.Now,if run a Bamboo plan (regular), my script runs perfectly. It can get the oc (openshift commands) on PATH (environment variables on Bamboo) for e.g. below command executes well by Bamboo plan :-

# include openshift in path
PATH=$PATH:/data/bamboo/openshift

/bin/sh ./portal/deploy.sh --build-number=${bamboo.buildNumber}

But, if I create a 'Deployment Project' and try to run the similar command, I always get the error as oc: not found

Complete error log:-

26-Jul-2019 20:21:27    -> Getting present working dir...
26-Jul-2019 20:21:27    /opt/bamboo-agent-root/bamboo-agent-home/xml-data/build-dir/518946826-518455357
26-Jul-2019 20:21:27    -> Deployment started...
26-Jul-2019 20:21:27    -> Bringing down the pod(s)...
26-Jul-2019 20:21:27    -> Recreating the pod(s)...
26-Jul-2019 20:21:27    -> Deployment completed on TST environment
26-Jul-2019 20:21:27    /opt/bamboo-agent-root/bamboo-agent-home/temp/518946826-518455357-517442402-ScriptBuildTask-7080740712063035315.sh: 6: /opt/bamboo-agent-root/bamboo-agent-home/temp/518946826-518455357-517442402-ScriptBuildTask-7080740712063035315.sh: oc: not found
26-Jul-2019 20:21:27    /opt/bamboo-agent-root/bamboo-agent-home/temp/518946826-518455357-517442402-ScriptBuildTask-7080740712063035315.sh: 10: /opt/bamboo-agent-root/bamboo-agent-home/temp/518946826-518455357-517442402-ScriptBuildTask-7080740712063035315.sh: oc: not found
26-Jul-2019 20:21:27    /opt/bamboo-agent-root/bamboo-agent-home/temp/518946826-518455357-517442402-ScriptBuildTask-7080740712063035315.sh: 13: /opt/bamboo-agent-root/bamboo-agent-home/temp/518946826-518455357-517442402-ScriptBuildTask-7080740712063035315.sh: oc: not found
26-Jul-2019 20:21:27    /opt/bamboo-agent-root/bamboo-agent-home/temp/518946826-518455357-517442402-ScriptBuildTask-7080740712063035315.sh: 13: /opt/bamboo-agent-root/bamboo-agent-home/temp/518946826-518455357-517442402-ScriptBuildTask-7080740712063035315.sh: oc: not found

This is what I'm trying to execute :-

PATH=$PATH:/data/bamboo/openshift
echo "-> Getting present working dir..."
echo $PWD
oc project dummyproject-tst
echo "-> Deployment started..."
echo "-> Bringing down the pod(s)..."
oc scale --replicas=0 deployment dummy-deployment
echo "-> Recreating the pod(s)..."
oc process -f ./openshift/templates/dummy-template.yaml -p IMAGE_TAG=190724.262 | oc apply -f -
echo "-> Deployment completed on TST environment"

I guess, the environment variable for openshift cli is not working even though I have declared in 1st line like PATH=$PATH:/data/bamboo/openshift

halfer
  • 19,824
  • 17
  • 99
  • 186
vinod827
  • 1,123
  • 1
  • 21
  • 45

1 Answers1

0

When I run into problems like that, it's usually because Bamboo somehow ends up with a non-login shell, and so your normal PATH is never built. (For more info on what a non-login shell is, see https://unix.stackexchange.com/a/46856/36922). I've worked around that issue a couple of ways:

  1. Use the source command to run /etc/profile at the beginning of your script. (YMMV on the actual path--this works on Ubuntu).
source /etc/profile
  1. Force a login shell manually by using the -l flag when you start your command. The easiest way is to dump your actual script into a file, and then manually execute that. Something like this:
echo "echo Hi!" > /tmp/tmp.sh
/bin/sh -l /tmp/tmp.sh

I'd recommend option 1 over option 2--it's a bit more maintainable, and a lot less confusing when someone else reads your script and has questions.

Chad
  • 1
  • 1