我有两个bash脚本。从第一个调用第二个。这是第二个,名为build_with_docker.sh
:
#!/bin/bash
VERSION=$1
BUILD_ID=$2
echo "-- build/platform/build_with_docker.sh --"
echo VERSION:$VERSION
echo BUILD_ID:$BUILD_ID
# override params
if [ -z "$VERSION" ]
then
echo "Failed to pass version :("
exit 1
fi
if [ -z "$BUILD_ID" ]
then
echo "Failed to pass BUILD_ID :("
fi
SOURCEID=$(docker build -q -f - --build-arg semver=$VERSION --build-arg build_id=$BUILD_ID $GOPATH/src/myproject < $DEVOPS/build/platform/Dockerfile.build)
echo $SOURCEID
我想从第一个脚本中调用上述脚本。这是第一个:
#!/bin/bash
VERSION=${1:-${VERSION}}
if [ -z "$VERSION" ]
then
echo "VERSION not defined in shell session, nor passed in as parameter"
exit 1
fi
if [ -z "$BUILD_ID" ]
then
BUILD_ID=$(date +%s)
echo "Setting build id to current date"
fi
# Builds, and outputs image to Docker's local image store
# example "sha256:59d19c43c86865aef8..."
DOCKER_IMAGE_ID=`$DEVOPS/build/platform/build_with_docker.sh ${VERSION} ${BUILD_ID}`
echo $DOCKER_IMAGE_ID
当我执行第一个脚本时,第二个脚本将永远不会执行,并且$DOCKER_IMAGE_ID
为空。如果我删除传递给第二个脚本的两个参数${VERSION}
和${BUILD_ID}
,则它可以工作。
编辑:$ DEVOPS是已经设置的环境变量
请告知。
谢谢