Using the notin operator
In the previous example, you blocked a task execution by using a when
expression. Sometimes, you might want to perform another task if a value is not matched. By using the notin
operator, you can add what would be similar to an else
statement. For this following example, you will add a You lose
message when the number is not 3
:
- Copy over the pipeline from
game.yaml
into a new file calledguess-notin.yaml
. Change the name of this new pipeline toguess-game-notin
, and keep everything else:apiVersion: tekton.dev/v1beta1 kind: Pipeline metadata: name: guess-game-notin spec: params: ... tasks: - name: win …
- At the end of this pipeline, add a new task called
lose
. This task object will reference the samelogger
task. As a parameter, it will takeYou lose
as the value fortext
:- name: lose params: - name: text ...