저장소 정보 및 토큰 검색
get_repo_params ()
get-repo-params 함수는 리포지토리 URL 및 리포지토리 토큰 경로가 제공되면 리포지토리 관련 정보를 검색하도록 설계되었습니다.
매개변수
get-repo-params 함수에는 다음 매개변수가 필요합니다.
repo_url리포지토리 URL. 매개 변수를 찾아야 하는 리포지토리의 올바른 URL을 입력합니다.repo_token_path저장소와 연관된 토큰에 대한 경로입니다.
출력
get-repo-params 함수는 파이프라인에서 제공됩니다. 이 함수는 다음 정보를 반환합니다:
repo_name: 리포지토리 이름입니다.repo_owner: 리포지토리의 사용자 또는 리포지토리 작성자.scm_type: 리포지토리의 소스 제어 관리 유형(Git, GRIT).api_url: API URL 리포지토리를 호스팅하는 Git 서비스와 연결됩니다.
함수 호출
read -r <repo_name> <repo_owner> <scm_type> <api_url> \
< <(get_repo_params "<repo_url>" "<token_path>")
읽기 명령에서 밑줄 변수(_)를 스크립트의 다음 부분에서 값이 삭제되거나 사용되지 않는 변수의 자리 표시자로 사용합니다.
read -r <repo_name> <_> <scm_type> <_> \
< <(get_repo_params "<repo_url>" "<token_path>")
이러한 변수를 스크립트에서 셸 변수로 사용하세요.
예
### <repo_url> = $EVIDENCE_LOCKER_URL
### <token_path> = ${WORKSPACE}/$EVIDENCE_TOKEN_PATH
source "${ONE_PIPELINE_PATH}"/tools/get_repo_params
read -r EVIDENCE_REPO_NAME EVIDENCE_REPO_ORG EVIDENCE_SCM_TYPE EVIDENCE_API_URL \
< <(get_repo_params "$EVIDENCE_LOCKER_URL" "${WORKSPACE}/$EVIDENCE_TOKEN_PATH")
### Printing the value of EVIDENCE_LOCKER_URL
echo "EVIDENCE_LOCKER_URL $EVIDENCE_LOCKER_URL"
get_repo_specific_token ()
get_repo_specific_token 함수는 앞서 사용한 URL 리포지토리와 연결된 토큰을 검색합니다. 리포지토리 토큰은 특정 리포지토리에 대한 액세스를 인증하고 권한을 부여합니다.
환경 특성 테이블에서 (git-token-[repo_name]-[repo_org]) 변수의 값을 선택합니다.
예
let repo_url = <repo_git_url> 여기서,
<repo_name> = compliance-app
<repo_org> = user_name
함수 호출
parameter
### repo_url
token=$(get_repo_specific_token "<repo_url>")
출력:
다음 출력이 생성됩니다.
echo "$repo_token"
예:
### parameter:
# <repo_url>: URL of repo of which token is required.
source "${ONE_PIPELINE_PATH}"/tools/get_repo_params
repo_url= <repo_url>
token=$(get_repo_specific_token "$repo_url")
### Output
# repo_token
echo "Repository Token: $token"
get_api_url ()
get_api_url 함수는 다양한 유형의 소스 코드 리포지토리에 적합한 API URL 를 결정합니다.
매개변수:
repo_url: 소스 코드 리포지토리의 URL.
함수 호출:
api_url=$(get_api_url "<repo_url>")
리턴값:
이 함수는 지정된 리포지토리에 대한 API URL 값을 표시합니다.
예:
source "${ONE_PIPELINE_PATH}/tools/get_repo_params"
repo_url= <repo_url>
api_url=$(get_api_url "$repo_url")
echo "API URL for $repo_url is: $api_url"
SCM 유형 및 해당 API URL:
-
GitHub 통합:
- SCM 유형:
github_integrated - API URL: <api_url>
- SCM 유형:
-
GitHub 통합:
- SCM 유형:
githubconsolidated - 통합 GitHub 저장소:
- API URL:
https://<repo_server_name>/api/v3(여기서<repo_server_name>는 리포지토리 URL 에서 추출한 것임)
- API URL:
- 비통합 GitHub 저장소:
- API URL:
https://api.github.com
- API URL:
- SCM 유형:
-
호스팅된 Git:
- SCM 유형:
hostedgit - API URL:
https://<repo_server_name>/api/v4(여기서<repo_server_name>는 리포지토리 URL 에서 추출한 것임)
- SCM 유형:
SCM 유형이 지원되는 유형 중 하나가 아닌 경우 경고 메시지가 표시됩니다.
get_repo_scm_type ()
이 함수는 지정된 리포지토리의 SCM(소스 코드 관리) 유형을 결정합니다 URL.
매개변수:
repo_url: SCM 유형을 결정해야 하는 리포지토리의 URL.
함수 호출:
scm_type=$(get_repo_scm_type "<repo_url>")
출력:
SCM 플랫폼을 나타내는 레이블로, 다음 중 하나일 수 있습니다:
- GitLab-hosted 리포지토리의 경우:
gitlab - GitHub-integrated 리포지토리의 경우:
github-기타 경우 (기본값: GitHub):github
사용법 예:
source "${ONE_PIPELINE_PATH}/tools/get_repo_params"
repository_url= <repo_url>
result=$(get_repo_scm_type "$repository_url")
echo "SCM Type: $result"
이 예에서는 앞서 제공한 리포지토리 URL 가 GitHub 와 통합되어 있으므로 github 를 출력 값으로 표시합니다.
get_repo_owner ()
이 함수는 앞서 제공된 Git 리포지토리 URL 에서 소유자 또는 하위 그룹 정보를 추출합니다.
매개변수:
repo_url: Git 리포지토리의 URL.
함수 호출:
Owner_name=$(get_repo_owner "<repo_url>")
출력:
- 리포지토리에서 추출한 소유자 또는 하위 그룹 정보 URL.
사용법 예:
source "${ONE_PIPELINE_PATH}/tools/get_repo_params"
repository_url= <repo_url>
owner=$(get_repo_owner "$repository_url")
echo "Repository Owner: $owner"
이 예에서는 GitHub 리포지토리 URL '사용자 이름' 계정 또는 하위 그룹을 호스트하기 때문에 출력으로 user_name 이 표시됩니다.
- 소유자를 찾을 수 없는 경우 URL 의 첫 번째 세그먼트를 소유자로 추출합니다.
get_repo_name ()
이 함수는 주어진 리포지토리 URL 에서 Git 리포지토리의 이름을 추출합니다.
매개변수:
repo_url: Git 리포지토리의 URL.
함수 호출:
Repo_name=$(get_repo_name "<repo_url>")
출력:
이 함수 호출은 URL 리포지토리에서 추출된 리포지토리 이름을 출력으로 표시합니다.
사용법 예:
source "${ONE_PIPELINE_PATH}/tools/get_repo_params"
repository_url= <repo_url>
repo_name=$(get_repo_name "$repository_url")
echo "Repository Name: $repo_name"
이 예에서는 제공된 리포지토리 URL 의 이름이 GitHub 에서 "compliance-app"이므로 compliance-app 을 출력합니다.
이름을 찾을 수 없으면 URL 의 두 번째에서 마지막 세그먼트를 이름으로 사용하려고 시도합니다.