我需要使用 Artifactory 文件信息完成一个 csv 文件,但是当我尝试生成它时,我在格式上遇到了一些问题。
为此,我在 Artifactory 上为每个组件获取文件夹中的文件列表,并获得每个组件的所有校验和:
function getArtifactoryMavenInfo {
completPath="$1$commandeAsk"
# get all files in one Artifactory folder => this is OK
list_MAVEN_files=($(curl -H "Content-Type: text/plain" -u XXX:XXX -X GET "$completPath" | jq ".files" | sed -n -e '/^.*\"uri\"\: \"/p' | sed 's/^.*\"uri\"\: \"\///' | sed 's/".*$//'))
# all_checksum will have all files with there checksums
all_checksum=""
for (( f=0; f<${#list_MAVEN_files[@]}; f++ )); do
filePath="$1/${list_MAVEN_files[f]}"
# all checksums have the good format => this is ok
checksums_MAVEN_sha1=($(curl "$filePath" | jq ".checksums.sha1" | sed 's/"//' | sed 's/"$//'))
checksums_MAVEN_md5=($(curl "$filePath" | jq ".checksums.md5" | sed 's/"//' | sed 's/"$//'))
checksums_MAVEN_sha256=($(curl "$filePath" | jq ".checksums.sha256" | sed 's/"//' | sed 's/"$//'))
# Trying to create an array with all files and there checksums => this is not sure ...
all_checksum+=$(echo "${list_MAVEN_files[f]} : sha1=${checksums_MAVEN_sha1} / md5=${checksums_MAVEN_md5} / sha256=${checksums_MAVEN_sha256}")
done
# put the previous array on a list => it will be the third column in the csv
finalListArtifactorySHA+=($(echo "$all_checksum"))
# put the path of the folder on a list => it will be for example the first column
finalListArtifactoryPath+=($(echo "$1/"))
}
这样我就有了我需要的所有信息。然后我尝试将所有这些放在一个 csv 文件中:
echo "Component name;Component version;Artifacts checksums;Artifactory path;Repo path" > $CSV_FILE_NAME
for (( i=0; i<${#finalListComponentName[@]}; i++ )); do
echo "${finalListComponentName[i]};${finalListComponentVersion[i]};${finalListArtifactorySHA[i]};${finalListArtifactoryPath[i]};${finalListRepoPath[i]}" >> $CSV_FILE_NAME
done
你能帮我么?我尝试了很多修改并检查了所有论坛,但我从来没有在我的 csv 输出中得到我需要的结果。
非常感谢您的帮助 !!!