问题描述
我使用以下脚本获取 GitLab 中组的描述。
脚本:
#! /bin/bash
GIT_API="https://git.xxxxxxxxxx.lk/api/v4"
GIT_TOKEN="xxxxxxxxxxxx"
curl -sS --request GET --header "PRIVATE-TOKEN: $GIT_TOKEN" "$GIT_API/groups/1079" | jq -r ".[] .description"
jq: error (at <stdin>:0): Cannot index number with string "description"
如何解决这个问题。
卷曲输出:
{
"id": 1079,"web_url": "https://git.xxxxxxxxxx.lk/groups/testdevops","name": "testdevops20","path": "testdevops","description": "Test_1","visibility": "private","share_with_group_lock": false,"require_two_factor_authentication": false,"two_factor_grace_period": 48,"project_creation_level": "developer","auto_devops_enabled": null,"subgroup_creation_level": "maintainer","emails_disabled": null,"mentions_disabled": null,"lfs_enabled": true,"default_branch_protection": 1,"avatar_url": null,"request_access_enabled": true,"full_name": "testdevops20","full_path": "testdevops","created_at": "2021-05-31T04:56:28.467Z","parent_id": null,"shared_with_groups": [],"runners_token": "Dw_LPVsbeChD6s6n1wRy","projects": []
}
解决方法
修改脚本如下:
#! /bin/bash
GIT_API="https://git.xxxxxxxxxx.lk/api/v4"
GIT_TOKEN="xxxxxxxxxxxx"
curl -sS --request GET --header "PRIVATE-TOKEN: $GIT_TOKEN" "$GIT_API/groups/1079" | jq -r ".description"
jq
命令在写为 jq -r ".description"
时有效。