Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash Jenkins如何在我的远程shell脚本中传递GIT_分支参数_Bash_Shell_Jenkins - Fatal编程技术网

Bash Jenkins如何在我的远程shell脚本中传递GIT_分支参数

Bash Jenkins如何在我的远程shell脚本中传递GIT_分支参数,bash,shell,jenkins,Bash,Shell,Jenkins,实际上,我需要在我的shell脚本中的post build action下使用GIT_BRANCH参数,该脚本将在我的远程ssh机器上运行我有echo GIT_BRANCH参数,但它是空的。有人能帮助我如何在我的远程shell脚本中传递我的环境变量吗 #!/bin/bash echo "Branch Name=>" $GIT_BRANCH if [ $GIT_BRANCH == 'origin/master' ] then DOCKERFILE_NAME='Dockerfi

实际上,我需要在我的shell脚本中的post build action下使用GIT_BRANCH参数,该脚本将在我的远程ssh机器上运行我有echo GIT_BRANCH参数,但它是空的。有人能帮助我如何在我的远程shell脚本中传递我的环境变量吗

#!/bin/bash

echo "Branch Name=>" $GIT_BRANCH

if [ $GIT_BRANCH == 'origin/master' ] then   
   DOCKERFILE_NAME='Dockerfile.master'    docker build -f
   $DOCKERFILE_NAME -t master_image:v1 .
elif [ $GIT_BRANCH=='origin/development' ] then   
   DOCKERFILE_NAME='Dockerfile.development'    docker build -f
   $DOCKERFILE_NAME -t development_image:v1 .
else
   echo "branch cannot be handle"
fi

echo "DOCKERFILE NAME:"$DOCKERFILE_NAME

正如您所知,GIT_分支未在远程计算机上设置,您需要将其作为脚本的参数传递。 脚本:

然后像下面那样运行它

ssh ${remote_address} ${script_path} $GIT_BRANCH
例如,远程地址为10.0.0.1,脚本路径为/var/lib/test.sh

ssh 10.0.0.1 /var/lib/test.sh $GIT_BRANCH

正如您所知,GIT_分支未在远程计算机上设置,您需要将其作为脚本的参数传递。 脚本:

然后像下面那样运行它

ssh ${remote_address} ${script_path} $GIT_BRANCH
例如,远程地址为10.0.0.1,脚本路径为/var/lib/test.sh

ssh 10.0.0.1 /var/lib/test.sh $GIT_BRANCH

如果通过ssh连接到远程服务器,还可以附加一些env变量-这需要对ssh服务器配置进行一些更改。如果您使用的是本机ssh,则可以执行类似的操作,然后使用sshuser@host“GIT_BRANCH=${GIT_BRANCH}”。没有试过,但可以工作。否则,请更新您的问题并提供有关构建的更多详细信息。如果您通过ssh连接到远程服务器,还可以附加一些env变量-这需要对ssh服务器配置进行一些更改。如果您使用的是本机ssh,则可以执行类似的操作,然后使用sshuser@host“GIT_BRANCH=${GIT_BRANCH}”。没有试过,但可以工作。否则,请更新您的问题并提供有关构建的更多详细信息。