«Как исправить ошибку« Синтаксическая ошибка рядом »в BASH» - PullRequest
0 голосов
/ 06 июня 2019

Я устанавливаю новое условие для запуска задания удаления, если оно существует, но не работает в производственном случае.

GNU bash, v4.3.48 (1) -релиз (x86_64-pc-linux-gnu)

docker run -e GO_DEPENDENCY_LABEL_PIPE='XXXXX' -e CREDENTIAL_NAME='production.XXXXX' -e KUBE_TOKEN='XXXXX' -v /go/pipelines/deploy-portal-site-data/helm:/helm --add-host=api.production.XXXXX:00.000.000.000 --rm -t --entrypoint /bin/bash docker.XXXXX.com.br/kubectl-prod:latest --login -c "kubectl config set-credentials production.XXXXX --token=XXXXX; VerifyJob=0; [[  -ge 1 ]] && kubectl -n production delete job portal-site-data-production || echo 'There is no job at the moment'"

Я ожидаю вывод чистой работы, но фактический вывод составляет

Creating /root/.helm/repository 
Creating /root/.helm/repository/cache 
Creating /root/.helm/repository/local 
Creating /root/.helm/starters 
Creating /root/.helm/cache/archive 
Creating /root/.helm/repository/repositories.yaml 
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com 
Adding local repo with URL: http://127.0.0.1:8879/charts 
$HELM_HOME has been configured at /root/.helm.
Not installing Tiller due to 'client-only' flag having been set
Happy Helming!
Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈ 
"gfn-helm-repo" has been added to your repositories
/bin/bash: -c: line 0: conditional binary operator expected
/bin/bash: -c: line 0: syntax error near `1'
/bin/bash: -c: line 0: `kubectl config set-credentials production.XXXXX --token=XXXXX; VerifyJob=0; [[  -ge 1 ]] && kubectl -n production delete job portal-site-data-production || echo 'There is no job at the moment''

Ответы [ 2 ]

2 голосов
/ 06 июня 2019
[[  -ge 1 ]]

Я думаю, что ошибка исходит от этой части команды.

Это проверка, если "undefined" больше или равен 1

1 голос
/ 07 июня 2019

Я удалил свой график helm delete portal-site-data-production --tiller-namespace production --purge

и поставил \ перед "

set -x
docker pull $DOCKER_HELM_PROD_IMAGE
docker run \
-e GO_DEPENDENCY_LABEL_PIPE='${GO_DEPENDENCY_LABEL_PIPE}' \
-e CREDENTIAL_NAME='${CREDENTIAL_NAME}' \
-e KUBE_TOKEN='${KUBE_TOKEN}' \
-v $PWD/helm:/helm \
--add-host=api.production.XXXXX:00.000.000.000 \
--rm -t --entrypoint /bin/bash \
$DOCKER_HELM_PROD_IMAGE \
--login -c "kubectl config set-credentials ${CREDENTIAL_NAME} --token=${KUBE_TOKEN}; VerifyJob=$(kubectl -n production get job| grep -c portal-site-data-production); \"[[ ${VerifyJob} -ge 1 ]]\" && kubectl -n production delete job portal-site-data-production || echo \"There is no job at the moment\""

Это нормально, спасибо всем большое.

...