Title: How do I check if DeploymentConfig exisit in batch script
Tags: azure;batch-file;azure-devops;openshift;openshift-client-tools
Question: I have written a pipeline in azure devops in ubuntu-latest agent to cater deployment to openshift.
I am able to get the script running in my pipeline as the first example
however i am trying to use script in windows-latest agent which is a batch script. However i am not able to tell if the following deployment config exist or not before deploying an application or updating the following image in windows platform.
My goal is to tell the pipeline that
if the deployment config exist ? update the image to the latest image
if the deployment config doesnt exist ? deploy as a new-app and create as deployment config
First Example:
In Linux / ubuntu i am able to:
echo '<===== Begin Deployment to Openshift =====&gt;'
echo '... Fetch DeploymentConfig Check ...'
TEM=&quot;$(oc get dc/myapp)&quot;
echo '=== Perform DeploymentConfig Check Check ==='
if [ -z &quot;$TEM&quot; ]
then
echo '<======== New Deployment ========&gt;'
oc new-app docker.hub/myname/myapp:$(newtag) --name myapp -n mynamespace --as-deployment-config || true
echo ' run rollout cancel cmd'
oc rollout cancel dc/myapp -n mynamespace || true
echo ' run set env cmd'
echo '<======== Deployment Completed ========&gt;'
else
echo '<======== Deployment Exist ========&gt;'
echo $TEM
echo '<==================================&gt;'
oc rollout pause dc/myapp -n mynamespace
oc tag docker.hub/myname/myapp:$(newtag) myapp:latest
oc rollout resume dc/myapp -n mynamespace
oc rollout latest dc/myapp -n mynamespace
oc rollout status dc/mynamespace -w -n mynamespace
echo '=== Image Updated ==='
fi
echo '<======== Deployment Completed ========&gt;'
In windows i tried the followings however it does not work here is my example of my snippets:
oc get dc/myapp &gt; temp.txt
dir /w/o/p
IF FOUND &quot;temp.txt&quot; ( echo 'found here' )
IF NOT FOUND &quot;temp.txt&quot; (echo 'not found here')
The output of the result:
Error from server (NotFound): deploymentconfigs.apps.openshift.io &quot;myapp&quot; not found
Volume in drive D is Temp
Directory of D:\a\1\s
[.]         [..]        [.download] temp.txt
1 File(s)              0 bytes
3 Dir(s)  14,822,907,904 bytes free
&quot;temp.txt&quot; was unexpected at this time.
##[error]Cmd.exe exited with code '255'.
I also try the following method however it does not work as well:
oc get dc/myapp || GOTO :deploynew
oc get dc/myapp &amp;&amp; GOTO :update
dir /w/o/p
:deploynew
echo 'deploy new'
:update
echo 'update here'
I also tried on this but it does not work as well:
FOR /F &quot;tokens=*&quot; %%g IN ('oc get dc/myapp') do SET VAR=&quot;%%g&quot;
IF /I &quot;%VAR%&quot; EQU &quot;1&quot; (
echo 'it is empty HERE'
IF NOT DEFINED %VAR% (
echo 'there is value HERE'
Hope to hear from a window batch expert.. can a kind soul help me thank you so much.
Output Format:
If consist:
NAME      REVISION   DESIRED   CURRENT   TRIGGERED BY
demo      6          1         0         config
If Empty:
NAME      REVISION   DESIRED   CURRENT   TRIGGERED BY
Comment: oc is a cli tool its the same as kubectl

Comment: This is the output:

Comment: If consist:
NAME      REVISION   DESIRED   CURRENT   TRIGGERED BY
demo      6          1         0         config
If Empty:
NAME      REVISION   DESIRED   CURRENT   TRIGGERED BY

Comment: @Gerhard i place it on the question for your reference

Comment: what is the standard output of the `oc` command?

Comment: yeah, but I want to know what the output is it provides, I do not have access to it, so not possible for me to know how to help you.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 6, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:11/08/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<azure><batch-file><azure-devops><openshift><openshift-client-tools>', 'Title': 'How do I check if DeploymentConfig exisit in batch script', 'ViewCount': 334, 'id': 69880546, 'user_AboutMe': None, 'user_AccountId': 4744091.0, 'user_DisplayName': 'isme', 'user_Reputation': 180.0, 'user_Views': 43.0, 'user_id': 3835865.0}}