A linter for tekton resource definitions
The only requirement is node (at least 12.0.0
).
$ npm install -g tekton-lint
tekton-lint
is parsing the passed files as yaml files, and checks the rules
on the resulting document set. More details on the pattern syntax.
Using tekton-lint
in watch mode will monitor for any changes in the provided paths and automatically run the linter again.
Options:
$ tekton-lint --watch # Run tekton-lint in watch mode
$ tekton-lint --version # Show version number
$ tekton-lint --help # Show help
$ tekton-lint --color / --no-color # Forcefully enable/disable colored output
$ tekton-lint --format # Format output. Available formatters: vscode (default) | stylish | json
$ tekton-lint --quiet # Report errors only - default: false
$ tekton-lint --max-warnings <Int> # Number of warnings to trigger nonzero exit code - default: -1
# exact file path
$ tekton-lint my-pipeline.yaml my-task.yaml
# globstar matching (note the quotes around the glob expression)
$ tekton-lint '**/*.yaml'
# multiple glob patterns
$ tekton-lint path/to/my/pipeline.yaml 'path/to/my/tasks/*.yaml'
# Watch mode
$ tekton-lint --watch '**/*.yaml'
tekton-lint
can be added as a Task:
// .vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Run tekton-lint in the workspace",
"type": "shell",
"command": "tekton-lint",
"args": [
"--watch",
"${workspaceFolder}/**/*.yaml" // Change this path to the path of your yaml files (this will watch for every yaml file in your currently open workspace)
],
"problemMatcher": [
{
"fileLocation": "absolute",
"pattern": [
{
"regexp": "^([^\\s].*):$",
"file": 1
},
{
"regexp": "^(error|warning|info)\\s+\\((\\d+,\\d+,\\d+,\\d+)\\):(.*)$",
"severity": 1,
"location": 2,
"message": 3,
"loop": true
}
],
"background": {
"activeOnStart": true,
"beginsPattern": "^File (.*) has been changed! Running Linter again!",
"endsPattern": "^Tekton-lint finished running!"
}
}
]
}
]
}
You can run this task from Terminal > Run Task... > Run tekton-lint:
Runs the linter on the provided globs
, and resolves to the list of found problems.
Each problem has a level
and a message
property. path
is the path to the
original file, loc
is an object which describes the location of the problem.
interface Problem {
level: 'warning' | 'error';
message: string;
path?: string;
loc?: {
range: [number, number];
startLine: number;
startColumn: number;
endLine: number;
endColumn: number;
};
}
const linter = require('tekton-lint');
const problems = await linter(['path/to/defs/**/*.yaml']);
for (const problem of problems) {
console.log(problem.level, problem.message)
}
Runs the linter on the provided parsed documents. Returns the list of found problems.
const linter = require('tekton-lint');
const problems = linter.lint([{
apiVersion: 'tekton.dev/v1beta1',
kind: 'Task',
metadata: {
name: 'my-task',
},
spec: {
steps: [],
},
}]);
for (const problem of problems) {
console.log(problem.level, problem.message)
}
These rules are straightforward, violations indicate that there's a good chance that you won't be able to run your
Pipeline
- Missing
Task
definitions - Missing
Condition
definitions - Missing
Pipeline
definitions - Missing
TriggerTemplate
definitions - Missing
TriggerBinding
definitions - Missing parameter declarations within
Task
s - Missing parameter declarations within
Pipeline
s - Missing parameter declarations within
TriggerTemplate
s - Missing volume definitions in
Task
s - Missing
Task
outputresult
s - Missing required
Pipeline
parameters inTriggerTemplate
s - Missing required
Task
parameters inPipeline
s - Missing required workspaces of
Task
s referenced inPipeline
s - Missing required workspaces of
Pipeline
s referenced inTriggerTemplate
s - Extra parameters passed to
Pipeline
s - Extra parameters passed to
Task
s - Invalid
runAfter
conditions - Invalid
resourceVersion
key - Duplicate resources (of all supported resource kinds)
- Duplicate parameters name in
Task
s - Duplicate environment variables in
Step
s - Duplicate
PipelineRun
's parameters name inTriggerTemplate
s - Duplicate parameters name in
TriggerBinding
s - Duplicate parameters name in
TriggerTemplate
s - Duplicate parameters name in
Pipeline
s - Missing
Task
parameter value inPipeline
s - Invalid
Task
,Pipeline
,TriggerTemplate
,Condition
parameter names (alpha-numeric characters,-
and_
and can only start with alpha characters and_
) - Invalid
Task
,Pipeline
,TriggerTemplate
parameter value types (must bestring
,multiline string
orarray of strings
) - Invalid
Task
parameter syntax (usingv1beta1
syntax inv1alpha1
defintions, and vice versa) - Invalid (undefined)
Workspace
references inTask
s ofPipeline
s - Missing referenced
Task
in anotherTask
's parameter inPipeline
s - Cycle detection in each pipelines task dependency graph (based on
runAfter
s,results
andresource -> inputs
)
If you violate these rules, the
Pipeline
is probably going to be just fine, these rules are more like a collection of best practices that we collected while we were working with tekton.
- Unused
Task
parameters - Unused
Condition
parameters - Unused
Pipeline
parameters - Unused
TriggerTemplate
parameters - Unpinned images in
Task
steps - kebab-case naming violations
Task
&Pipeline
definitions withtekton.dev/v1alpha1
apiVersion
- Missing
TriggerBinding
parameter values - Usage of deprecated
Condition
instead ofWhenExpression
- Usage of deprecated resources (resources marked with
tekton.dev/deprecated
label)
You can configure tekton-lint
with a configuration file (.tektonlintrc.yaml
) in your project's directory. You can decide which rules are enabled and at what error level.
The configuration file should follow this format:
---
rules:
rule-name: error | warning | off
Example .tektonlintrc.yaml
file:
---
rules:
no-duplicate-param: error
no-unused-param: warning
no-deprecated-resource: off
tekton-lint
will look for a configuration file named .tektonlintrc.yaml
in the directory where you run the command. If the configuration file is not present, tekton-lint
will use the default configuration.