首页 > 解决方案 > 用于在harbor中创建多个项目的bash脚本

问题描述

我想使用 API 在港口创建多个项目。所以我有 5 个项目要在文本文件中创建

项目.txt

projects: abcd
          efgh
          ijkl
          mnop
          qrst

create_projects.sh

#!/bin/bash

DIR=$( cd "$( dirname "$BASH_SOURCE[0]}" )" && pwd )


while read p 
do
    curl --location --request POST 'https://harbor.rl.com/api/v2.0/projects' --header 'Content-Type: application/json' --header 'X-Resource-Name-In-Location: true' --header 'Authorization: Basic jhgkyyktfkghfgfhfgh=' --data-raw '{ 
"project_name": $p,
"public": true,
"metadata": { 
"public": "true", 
"prevent_vul": "true",
"auto_scan": "true"
},
"storage_limit": -1 
}'
done < "$DIR/../assets/projects.txt"

我创建了这样的 bash 脚本。请建议我们如何通过脚本在港口回购中创建这五个项目

标签: linuxbashshellsh

解决方案


推荐阅读