字符串中提取文件名,并赋值给变量
#提取文件名成功
projects="D:/Project/Program/IDEAWorkspace/myauto/automation-test/src/main/java/com/welab/automation/projects/channel/feature/abc.feature"
filename=${projects##*/} #变量赋值 等号两边不要空格
echo "${filename}" #abc.feature
上传feature使用的脚本
#!/bin/bash
zstoken="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjb250ZXh0Ijp7ImJhc2VVcmwiOiJodHRwczovL3dlbGFiYmFuay5hdGxhc3NpYW4ubmV0IiwidXNlciI6eyJhY2NvdW50SWQiOiI2Mjk4NzAxMDk1ODJiODAwNmZjNWI3ODAifX0sImlzcyI6ImNvbS5rYW5vYWgudGVzdC1tYW5hZ2VyIiwic3ViIjoiZmYzNWI4MzctNTIyOS0zZmFiLTgwM2UtN2EyN2ExMGFlZGVjIiwiZXhwIjoxNzAwMjAzMzEwLCJpYXQiOjE2Njg2NjczMTB9.qBPibMSKKtJJb9has09MEJXCpM4sd1pV6Ko0LDrYKLo"
#FILES="./zephyrScaleTestCase/*"
#for f in $FILES
#for f in ./zephyrScaleTestCase/*.feature ./zephyrScaleTestCase/**/*.feature
projects="D:/Project/Program/IDEAWorkspace/myauto/automation-test/src/main/java/com/welab/automation/projects"
for f in ${projects}/**/**/**/*.feature ${projects}/**/**/**/**/*.feature ${projects}/**/**/**/**/**/*.feature ${projects}/**/**/**/**/**/**/*.feature ${projects}/**/**/**/**/**/**/**/*.feature
do
fileName=$(basename $f)#just file name ##fn=$(sed 's/.*\///' <<< $f)alternative to filter filename from full path
dirName=$(dirname $f)#dir path
partialName=${f#${projects}}
#extension=${fileName##*.} #extension of file
##featureText=`cat $f` #for checking if the "Feature:" line is commented
featureText=`cat $f | tr '\r\n' "#"`
featureText=$(sed 's/@/#>/g' <<< $featureText)
featureText=$(sed 's/"/`>/g' <<< $featureText)
featureText=$(sed 's/\x27/`>/g' <<< $featureText)
featureText=$(sed 's/##/\<br\>/g' <<< $featureText)
echo "${partialName}"
echo "${fileName}"
if ! [[ $fileName = *"TAT-T"* ]]; then # if fileName doesn't contain "TAT-T"
#casename=${f##*/}
# echo "${casename}"
#create test case, save test case key
testCaseKey=$(curl -k -H "Authorization: Bearer ${zstoken}" -X POST "https://api.zephyrscale.smartbear.com/v2/testcases" -H "Content-Type: application/json" -d "{\"projectKey\":\"TAT\",\"name\":\"${partialName}\"}" | jq --raw-output '.key')# > choco install jq
#create test script
echo "${testCaseKey}"
curl -k -H "Authorization: Bearer ${zstoken}" -X POST "https://api.zephyrscale.smartbear.com/v2/testcases/${testCaseKey}/testscript" -H "Content-Type: application/json" -d "{\"type\":\"plain\",\"text\":\"${featureText}\"}"
#add test case key as prefix
mv -f "$f" "${dirName}/${testCaseKey}_${fileName}"
#write automated test case key and path to appendix
appendix=`cat ./zephyrScaleTestCase/appendix.json` #let initialize the content of appendix.json to be "[]" (omit the double quotes)
# need to revise test case key, path
echo $(jq --null-input --argjson a "$appendix" '$a + [{"autoTestCaseKey": "'${testCaseKey}'", "manualTestCaseKey": "", "path": "'${dirName}/${testCaseKey}_${fileName}'"}]') > ./zephyrScaleTestCase/appendix.json
fi
done
echo `cat ./zephyrScaleTestCase/appendix.json`