3.4. 認証された Git API でのリモートパイプライン、タスク、またはステップアクションの指定
Git リゾルバーを使用して、Git リポジトリーからリモートパイプライン、タスク、または StepAction
定義を指定できます。リポジトリーには、パイプラインまたはタスクを定義する YAML ファイルが含まれている必要があります。ユーザー認証をサポートする認証済み API を使用すると、リポジトリーに安全にアクセスできます。
3.4.1. 認証された API の Git リゾルバーの設定
認証されたソースコントロール管理 (SCM) API の場合は、認証された Git 接続の設定を指定する必要があります。
go-scm
ライブラリーでサポートされている Git リポジトリープロバイダーを使用できます。すべての go-scm
実装が Git リゾルバーでテストされているわけではありませんが、次のプロバイダーが動作することが確認されています。
-
github.com
および GitHub Enterprise -
gitlab.com
およびセルフホスト Gitlab - Gitea
- Bitbucket データセンター
- Bitbucket Cloud
- 認証された SCM API を使用して Git 接続を設定できます。クラスター上のすべてのユーザーが 1 つのリポジトリーにアクセスできるようにセキュリティートークンを提供できます。さらに、特定のパイプラインまたはタスクに対して異なる SCM プロバイダーとトークンを指定することもできます。
- 認証された SCM API を使用するように Git リゾルバーを設定すると、匿名の Git クローン参照を使用してパイプラインとタスクを取得することもできます。
手順
TektonConfig
カスタムリソースを編集するには、次のコマンドを入力します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc edit TektonConfig config
$ oc edit TektonConfig config
TektonConfig
カスタムリソースで、pipeline.git-resolver-config
仕様を編集します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow apiVersion: operator.tekton.dev/v1alpha1 kind: TektonConfig metadata: name: config spec: pipeline: git-resolver-config: default-revision: main fetch-timeout: 1m scm-type: github server-url: api.internal-github.com api-token-secret-name: github-auth-secret api-token-secret-key: github-auth-key api-token-secret-namespace: github-auth-namespace default-org: tektoncd
apiVersion: operator.tekton.dev/v1alpha1 kind: TektonConfig metadata: name: config spec: pipeline: git-resolver-config: default-revision: main
1 fetch-timeout: 1m
2 scm-type: github
3 server-url: api.internal-github.com
4 api-token-secret-name: github-auth-secret
5 api-token-secret-key: github-auth-key
6 api-token-secret-namespace: github-auth-namespace
7 default-org: tektoncd
8 - 1
- 何も指定されていない場合に使用するデフォルトの Git リビジョン。
- 2
- 単一の Git クローン解決にかかる最大時間は、たとえば、
1m
、2s
、700ms
です。Red Hat OpenShift Pipelines は、すべての解決リクエストに対して 1 分のグローバル最大タイムアウトも適用します。 - 3
- SCM プロバイダーのタイプ。
- 4
- 認証された SCM API で使用するベース URL。
github.com
、gitlab.com
、または Bitbucket Cloud を使用している場合、この設定は必要ありません。 - 5
- SCM プロバイダー API トークンを含むシークレットの名前。
- 6
- トークンを含むトークンシークレット内のキー。
- 7
- トークンシークレットを含む namespace (
default
でない場合)。 - 8
- オプション: 認証された API を使用する場合のリポジトリーのデフォルトの組織。この組織は、リゾルバーパラメーターで組織を指定しない場合に使用されます。
認証された SCM API を使用するには、scm-type
、api-token-secret-name
、および api-token-secret-key
設定が必要です。
3.4.2. 複数の Git プロバイダーの設定
複数の Git プロバイダーを設定するか、同じ Git プロバイダーに複数の設定を追加して、異なるタスク実行とパイプライン実行で使用できます。
一意の識別子鍵の接頭辞を使用して、TektonConfig
カスタムリソース (CR) に詳細を追加します。
手順
次のコマンドを実行して、
TektonConfig
CR を編集します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc edit TektonConfig config
$ oc edit TektonConfig config
TektonConfig
CR で、pipeline.git-resolver-config
仕様を編集します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow apiVersion: operator.tekton.dev/v1alpha1 kind: TektonConfig metadata: name: config spec: # ... pipeline: git-resolver-config: # configuration 1 fetch-timeout: "1m" default-url: "https://github.com/tektoncd/catalog.git" default-revision: "main" scm-type: "github" server-url: "" api-token-secret-name: "" api-token-secret-key: "" api-token-secret-namespace: "default" default-org: "" # configuration 2 test1.fetch-timeout: "5m" test1.default-url: "" test1.default-revision: "stable" test1.scm-type: "github" test1.server-url: "api.internal-github.com" test1.api-token-secret-name: "test1-secret" test1.api-token-secret-key: "token" test1.api-token-secret-namespace: "test1" test1.default-org: "tektoncd" # configuration 3 test2.fetch-timeout: "10m" test2.default-url: "" test2.default-revision: "stable" test2.scm-type: "gitlab" test2.server-url: "api.internal-gitlab.com" test2.api-token-secret-name: "test2-secret" test2.api-token-secret-key: "pat" test2.api-token-secret-namespace: "test2" test2.default-org: "tektoncd-infra" # ...
apiVersion: operator.tekton.dev/v1alpha1 kind: TektonConfig metadata: name: config spec: # ... pipeline: git-resolver-config: # configuration 1
1 fetch-timeout: "1m" default-url: "https://github.com/tektoncd/catalog.git" default-revision: "main" scm-type: "github" server-url: "" api-token-secret-name: "" api-token-secret-key: "" api-token-secret-namespace: "default" default-org: "" # configuration 2
2 test1.fetch-timeout: "5m" test1.default-url: "" test1.default-revision: "stable" test1.scm-type: "github" test1.server-url: "api.internal-github.com" test1.api-token-secret-name: "test1-secret" test1.api-token-secret-key: "token" test1.api-token-secret-namespace: "test1" test1.default-org: "tektoncd" # configuration 3
3 test2.fetch-timeout: "10m" test2.default-url: "" test2.default-revision: "stable" test2.scm-type: "gitlab" test2.server-url: "api.internal-gitlab.com" test2.api-token-secret-name: "test2-secret" test2.api-token-secret-key: "pat" test2.api-token-secret-namespace: "test2" test2.default-org: "tektoncd-infra" # ...
警告.
記号が付いたconfigKey
値はサポートされません。.
シンボルを含むconfigKey
値を渡そうとすると、値を渡したTaskRun
またはPipelineRun
リソースの実行に失敗します。
3.4.3. 認証された SCM API で Git リゾルバーを使用したリモートパイプライン、タスク、またはステップアクションの指定
パイプライン実行を作成するときに、認証された SCM API を使用して Git リポジトリーからリモートパイプラインを指定できます。パイプラインまたはタスク実行を作成するときに、Git リポジトリーからリモートタスクを指定できます。タスク内でステップを作成するときに、Git リポジトリーからリモート StepAction
定義を参照できます。
前提条件
- 認証された SCM API を使用する場合は、Git リゾルバーに対して認証された Git 接続を設定する必要があります。
手順
Git リポジトリーからリモートパイプライン、タスク、または
StepAction
定義を指定するには、pipelineRef
、taskRef
、またはstep.ref
仕様で次の参照形式を使用します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow ... ...
# ... resolver: git params: - name: org value: <git_organization_name> - name: repo value: <git_repository_name> - name: revision value: <branch_name> - name: pathInRepo value: <path_in_repository> # ...
表3.4 Git リゾルバーでサポートされているパラメーター パラメーター 説明 値の例 org
認証された SCM API を使用する場合のリポジトリーの組織。
tektoncd
repo
認証された SCM API を使用する場合のリポジトリー名。
test-infra
revision
リポジトリー内の Git リビジョン。ブランチ名、タグ名、またはコミット SHA ハッシュを指定できます。
aeb957601cf41c012be462827053a21a420befca
main
v0.38.2
pathInRepo
リポジトリー内の YAML ファイルのパス名。
task/golang-build/0.3/golang-build.yaml
注記リポジトリーのクローンを作成して匿名で取得するには、
url
パラメーターを使用します。認証された SCM API を使用するには、repo
パラメーターを使用します。url
パラメーターとrepo
パラメーターを同時に指定しないでください。パイプラインまたはタスクに追加のパラメーターが必要な場合は、パイプライン、パイプライン実行、またはタスク実行の仕様の
params
セクションでこれらのパラメーターの値を指定します。pipelineRef
またはtaskRef
仕様のparams
セクションには、リゾルバーがサポートするパラメーターのみを含める必要があります。
例
次のパイプライン実行の例では、Git リポジトリーからリモートパイプラインを参照します。
apiVersion: tekton.dev/v1 kind: PipelineRun metadata: name: git-pipeline-reference-demo spec: pipelineRef: resolver: git params: - name: org value: tektoncd - name: repo value: catalog - name: revision value: main - name: pathInRepo value: pipeline/simple/0.1/simple.yaml params: - name: name value: "testPipelineRun" - name: sample-pipeline-parameter value: test
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: git-pipeline-reference-demo
spec:
pipelineRef:
resolver: git
params:
- name: org
value: tektoncd
- name: repo
value: catalog
- name: revision
value: main
- name: pathInRepo
value: pipeline/simple/0.1/simple.yaml
params:
- name: name
value: "testPipelineRun"
- name: sample-pipeline-parameter
value: test
次のパイプラインの例では、Git リポジトリーからリモートタスクを参照します。
apiVersion: tekton.dev/v1 kind: Pipeline metadata: name: pipeline-with-git-task-reference-demo spec: tasks: - name: "git-task-reference-demo" taskRef: resolver: git params: - name: org value: tektoncd - name: repo value: catalog - name: revision value: main - name: pathInRepo value: task/git-clone/0.6/git-clone.yaml params: - name: sample-task-parameter value: test
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: pipeline-with-git-task-reference-demo
spec:
tasks:
- name: "git-task-reference-demo"
taskRef:
resolver: git
params:
- name: org
value: tektoncd
- name: repo
value: catalog
- name: revision
value: main
- name: pathInRepo
value: task/git-clone/0.6/git-clone.yaml
params:
- name: sample-task-parameter
value: test
次のタスク実行例では、Git リポジトリーからリモートタスクを参照します。
apiVersion: tekton.dev/v1 kind: TaskRun metadata: name: git-task-reference-demo spec: taskRef: resolver: git params: - name: org value: tektoncd - name: repo value: catalog - name: revision value: main - name: pathInRepo value: task/git-clone/0.6/git-clone.yaml params: - name: sample-task-parameter value: test
apiVersion: tekton.dev/v1
kind: TaskRun
metadata:
name: git-task-reference-demo
spec:
taskRef:
resolver: git
params:
- name: org
value: tektoncd
- name: repo
value: catalog
- name: revision
value: main
- name: pathInRepo
value: task/git-clone/0.6/git-clone.yaml
params:
- name: sample-task-parameter
value: test
以下のタスク例には、Git リポジトリーから StepAction
定義を参照するステップが含まれています。
apiVersion: tekton.dev/v1 kind: Task metadata: name: git-stepaction-reference-demo spec: steps: - name: example-step ref: resolver: git - name: org value: openshift-pipelines - name: repo value: tektoncd-catalog - name: revision value: p - name: pathInRepo value: stepactions/stepaction-git-clone/0.4.1/stepaction-git-clone.yaml params: - name: sample-stepaction-parameter value: test
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: git-stepaction-reference-demo
spec:
steps:
- name: example-step
ref:
resolver: git
- name: org
value: openshift-pipelines
- name: repo
value: tektoncd-catalog
- name: revision
value: p
- name: pathInRepo
value: stepactions/stepaction-git-clone/0.4.1/stepaction-git-clone.yaml
params:
- name: sample-stepaction-parameter
value: test
3.4.4. 複数の Git プロバイダーの指定
TaskRun
および PipelineRun
リソースを作成するときに、一意の configKey
パラメーターを渡すことで、複数の Git プロバイダーを指定できます。
configKey
パラメーターが渡されない場合、デフォルト設定が使用されます。configKey
の値を default
に設定して、デフォルト設定を指定することもできます。
.
記号が付いた configKey
値はサポートされません。.
シンボルを含む configKey
値を渡そうとすると、値を渡した TaskRun
または PipelineRun
リソースの実行に失敗します。
前提条件
-
Tektonconfig
カスタムリソースを使用して複数の Git プロバイダーを設定します。詳細は、「複数の Git プロバイダーの設定」を参照してください。
手順
Git プロバイダーを指定するには、
pipelineRef
およびtaskRef
仕様で以下の参照形式を使用します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow ... ...
# ... resolver: git params: # ... - name: configKey value: <your_unique_key>
1 # ...
- 1
- 設定キーのいずれかに一致する一意のキー (例:
test1
)。
3.4.5. Git リゾルバーの設定を上書きする認証済み SCM API を使用した Git リゾルバーでのリモートパイプラインまたはタスクの指定
特定のパイプライン実行またはタスクの初期設定をオーバーライドして、さまざまなユースケースに応じて動作をカスタマイズできます。この方法を使用して、TektonConfig
カスタムリソース (CR) で設定されていない認証済みプロバイダーにアクセスできます。
次のタスク実行例では、以前のリゾルバー設定をオーバーライドする Git リポジトリーからのリモートタスクを参照します。
apiVersion: tekton.dev/v1beta1 kind: TaskRun metadata: name: git-task-reference-demo spec: taskRef: resolver: git params: - name: org value: tektoncd - name: repo value: catalog - name: revision value: main - name: pathInRepo value: task/git-clone/0.6/git-clone.yaml - name: token value: my-secret-token - name: tokenKey value: token - name: scmType value: github - name: serverURL value: https://ghe.mycompany.com
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: git-task-reference-demo
spec:
taskRef:
resolver: git
params:
- name: org
value: tektoncd
- name: repo
value: catalog
- name: revision
value: main
- name: pathInRepo
value: task/git-clone/0.6/git-clone.yaml
- name: token
value: my-secret-token
- name: tokenKey
value: token
- name: scmType
value: github
- name: serverURL
value: https://ghe.mycompany.com
パラメーター | 説明 | 値の例 |
---|---|---|
| リポジトリーの組織。 |
|
repo | リポジトリー名。 | catalog |
revision | リポジトリー内の Git リビジョン。ブランチ名、タグ名、またはコミット SHA ハッシュを指定できます。 | main |
pathInRepo | リポジトリー内の YAML ファイルのパス名。 | task/git-clone/0.6/git-clone.yaml |
トークン (token) | 認証に使用されるシークレット名。 | my-secret-token |
tokenKey | トークンのキー名。 | トークン (token) |
scmType | SCM (ソースコントロール管理) システムのタイプ。 | github |
serverURL | リポジトリーをホストしているサーバーの URL。 |
|