3.3. 匿名 Git クローンでのリモートパイプライン、タスク、またはステップアクションの指定
Git リゾルバーを使用して、Git リポジトリーからリモートパイプライン、タスク、または StepAction
定義にアクセスできます。リポジトリーには、パイプラインまたはタスクを定義する YAML ファイルが含まれている必要があります。匿名アクセスの場合、認証情報を必要とせずにリゾルバーを使用してリポジトリーを複製できます。
3.3.1. 匿名 Git クローン作成用の Git リゾルバーの設定
匿名 Git クローン作成を使用する場合は、Git リポジトリーからリモートパイプラインとタスクをプルするためのデフォルトの Git リビジョン、フェッチタイムアウト、およびデフォルトのリポジトリー URL を設定できます。
手順
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 default-url: https://github.com/tektoncd/catalog.git
apiVersion: operator.tekton.dev/v1alpha1 kind: TektonConfig metadata: name: config spec: pipeline: git-resolver-config: default-revision: main
1 fetch-timeout: 1m
2 default-url: https://github.com/tektoncd/catalog.git
3
3.3.2. 匿名クローン作成に Git リゾルバーを使用したリモートパイプライン、タスク、またはステップアクションの指定
パイプライン実行を作成するときに、匿名クローンを使用して Git リポジトリーからリモートパイプラインを指定できます。パイプラインまたはタスク実行を作成するときに、Git リポジトリーからリモートタスクを指定できます。タスク内でステップを作成するときに、Git リポジトリーからリモート StepAction
定義を参照できます。
手順
Git リポジトリーからリモートパイプライン、タスク、または
StepAction
定義を指定するには、pipelineRef
、taskRef
、またはstep.ref
仕様で次の参照形式を使用します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow ... ...
# ... resolver: git params: - name: url value: <git_repository_url> - name: revision value: <branch_name> - name: pathInRepo value: <path_in_repository> # ...
表3.3 Git リゾルバーでサポートされているパラメーター パラメーター 説明 値の例 url
匿名クローン作成を使用する場合のリポジトリーの URL。
https://github.com/tektoncd/catalog.git
revision
リポジトリー内の Git リビジョン。ブランチ名、タグ名、またはコミット SHA ハッシュを指定できます。
aeb957601cf41c012be462827053a21a420befca
main
v0.38.2
pathInRepo
リポジトリー内の YAML ファイルのパス名。
task/golang-build/0.3/golang-build.yaml
注記リポジトリーのクローンを作成して匿名で取得するには、
url
パラメーターを使用します。url
パラメーターとrepo
パラメーターを同時に指定しないでください。パイプラインまたはタスクに追加のパラメーターが必要な場合は、これらのパラメーターを
params
に指定します。
例
次のパイプライン実行の例では、Git リポジトリーからリモートパイプラインを参照します。
apiVersion: tekton.dev/v1beta1 kind: PipelineRun metadata: name: git-pipeline-reference-demo spec: pipelineRef: resolver: git params: - name: url value: https://github.com/tektoncd/catalog.git - 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/v1beta1
kind: PipelineRun
metadata:
name: git-pipeline-reference-demo
spec:
pipelineRef:
resolver: git
params:
- name: url
value: https://github.com/tektoncd/catalog.git
- 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: url value: https://github.com/tektoncd/catalog.git - 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: url
value: https://github.com/tektoncd/catalog.git
- 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/v1beta1 kind: TaskRun metadata: name: git-task-reference-demo spec: taskRef: resolver: git params: - name: url value: https://github.com/tektoncd/catalog.git - 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/v1beta1
kind: TaskRun
metadata:
name: git-task-reference-demo
spec:
taskRef:
resolver: git
params:
- name: url
value: https://github.com/tektoncd/catalog.git
- 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: url value: https://github.com/openshift-pipelines/tektoncd-catalog.git - 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: url
value: https://github.com/openshift-pipelines/tektoncd-catalog.git
- 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