简体   繁体   English

sed命令的Jenkinfile ssh问题

[英]Jenkinfile ssh issue with sed command

I have written one Jenkinsfile and in one step I am stuck, that is basically deploy stage. 我已经编写了一个Jenkinsfile,但停留在第一步中,那基本上是部署阶段。 In deploy stage there is a step where I have to ssh into one server and run couple of commands. 在部署阶段,有一个步骤必须将ssh放入一台服务器并运行几个命令。 Earlier it was working fine, but when i add sed command with some regex then Jenkins is showing syntax error. 之前它工作正常,但是当我用一些正则表达式添加sed命令时,Jenkins显示语法错误。 Below is the snippet. 以下是代码段。

                steps {
                      sshagent ( credentials: []) {

sh '''
echo "Tag=miqp-server_${BUILD_NUMBER}" > sshenv
echo "target=${DeployTo}" >> sshenv
scp sshenv root@SERVERIP:~/.ssh/environment
ssh -T -o StrictHostKeyChecking=no -l root SERVERIP <<'EOF'

#DEPLOYMENT_NAME="miqp-server-dep"
#CONTAINER_NAME="miqp-server-dev"
#NEW_DOCKER_IMAGE="2xxxxxxxxxx6.dkr.ecr.us-east-1.amazonaws.com/miqp-devops:${Tag}"
RELEASE_NAME=miqp-server-dep

if [ "${target}" = "None" ]
then
  echo "No deployment to K8s"
else

cd /root/kubernetes-ingress/dev/miqp-server-dep/
sed -i "s/^\([[:space:]]*tag:[[:space:]]*\).*/\1$Tag/" values.yaml
helm upgrade -f values.yaml $RELEASE_NAME miqp-server-dep.0.1.0.tgz

#kubectl set image deployment/$DEPLOYMENT_NAME $CONTAINER_NAME=$NEW_DOCKER_IMAGE -n devops-dev
#kubectl rollout status deployment $DEPLOYMENT_NAME -n devops-dev

fi
EOF'''

And the error Jenkins throwing is 詹金斯抛出的错误是

WorkflowScript: 156: unexpected char: '\' @ line 156, column 13.
   sed -i "s/^\([[:space:]]*tag:[[:space:]]*\).*/\1$Tag/" values.yaml
               ^

1 error

Hey I have solved the issue by giving escape character 嘿,我已经通过提供转义字符解决了这个问题

sed -i "s/^\([[:space:]]*tag:[[:space:]]*\).*/\1$Tag/" values.yaml 

sed -i "s/^\\([[:space:]]*tag:[[:space:]]*\\).*/\\1$Tag/" values.yaml

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM