Jenkinsfile Pipeline Generator
Create a declarative Jenkinsfile without remembering every directive: set the agent, environment, options and stages, preview the stage view, and check or import an existing file.
S'executa al teu navegador. Els fitxers mai no surten del dispositiu. Mira com comprovar-ho
…
Com es fa
- 1Choose a template
Start from Node.js, Maven, Docker or a blank pipeline, or import a Jenkinsfile.
- 2Set the agent
Pick any, none, a label, a Docker image, a Dockerfile or a Kubernetes pod.
- 3Add environment
Enter variables and credential references, options, parameters and triggers.
- 4Build the stages
Write steps, add when conditions, input approvals and parallel branches.
- 5Preview
Simulate a branch or tag in the stage view and fix every issue.
- 6Save the file
Copy or download the Jenkinsfile and commit it to the repository root.
Sobre aquesta eina
A Jenkinsfile stored in the repository describes the build as code, and the declarative syntax keeps it readable by fixing the order and meaning of each section. This generator writes that file from forms. At the pipeline level you choose the agent: any executor, none (so each stage picks its own), a node label, a Docker image with run arguments, a Dockerfile in the repository or a Kubernetes pod template. The environment table writes plain variables and credentials('id') references, the options panel covers timeout, build discarder, timestamps, retry and disableConcurrentBuilds, and you can add parameters, cron or pollSCM triggers, upstream triggers, tools such as a named Maven or JDK installation and shared libraries. Each stage has steps, its own agent and environment, a when block with branch globs, tag builds, changesets and Groovy expressions, an input approval, a stage timeout and retry, and post actions. Any stage can be split into parallel branches with failFast. Steps are written one per line; a line that starts with a dollar sign becomes an sh step and a line that starts with a greater-than sign becomes a Windows bat step, so you do not have to quote shell commands yourself. A snippet bar inserts common blocks such as withCredentials, sshagent, junit and archiveArtifacts.
Checking and importing a Jenkinsfile
The checker parses Groovy blocks while skipping strings, triple-quoted strings and comments, so a brace inside a string never confuses it. It reports unbalanced braces with the line where the block was opened, a missing agent or stages section, sections that are not allowed directly inside pipeline or a stage, a stage with no steps, two stages with the same name, nested parallel blocks, unknown when conditions and post conditions that do not exist, such as finally. It also catches Groovy if, for and def statements outside a script block, which a declarative pipeline rejects. Two security checks look for secrets written directly into the file and for credentials interpolated in a double-quoted sh string, where Groovy expands the secret before the shell runs and the value can leak into the build log or process list. Import reads a declarative Jenkinsfile back into the form; scripted node { } pipelines are recognised and refused, and nested stage groups or matrix blocks are kept as raw text so nothing is lost.
Stage view preview
The stage view draws the stages left to right, stacks parallel branches in one column and adds a final post box listing the conditions you used. Type a branch name or a tag to simulate a build: stages whose when branch pattern does not match, or that need a tag build, are greyed out, and the table explains each decision. Expressions and input steps are marked as decided at run time.
Worked example
Load the Node.js template. The Jenkinsfile has 80 lines: a docker agent using node:22-alpine with an npm cache volume, CI set to true, NPM_TOKEN read with credentials('npm-publish-token'), four options, a RUN_E2E boolean parameter and four stages. The Checks stage runs Lint, Unit tests and E2E in parallel with failFast true, and E2E only runs when params.RUN_E2E is true. The Publish stage only runs on main and waits for an input approval. The checker reports no problems. Set the simulated branch to feature/login and the stage view shows Install, Checks and Build running and Publish skipped. Now open the broken example in check mode: it has 7 errors, 2 warnings and 1 note, including the unclosed pipeline block, a stage named Build twice, the unknown when condition branchName, an if statement outside script and a post condition called finally.
Limits
The checker is a static reading of declarative syntax, not the Jenkins validator: it does not know which plugins your controller has, so steps from missing plugins are not reported, and Groovy inside script blocks is not compiled. Credentials IDs are not looked up. Use the Replay feature or the declarative linter endpoint on your Jenkins server before merging.
Exemple resolt
Node.js template: 80 lines, 4 stages with 3 parallel checks; on feature/login the Publish stage is skipped; the broken file shows 7 errors and 2 warnings.
En resum
- Categoria: Desenvolupament i dades
- S'executa al navegador, sense registre, sense pujar res.
- La informació que introdueixes es queda al dispositiu.
- Disponible en anglès.
- Contingut revisat per última vegada:
- Font oficial: Jenkins User Handbook: Pipeline Syntax
Preguntes freqüents
Should I choose declarative or scripted pipeline syntax?
Declarative, for most projects. It has a fixed structure, clear stage views and better error messages. Scripted pipelines are plain Groovy and suit unusual flows; you can still use a script block inside a declarative stage.
How do I use a Jenkins credential safely?
Reference it with credentials('id') in environment or withCredentials in a step, and use the variable inside single-quoted sh strings so the shell expands it and Jenkins can mask it in the log.
What does agent none at the top do?
No executor is held for the whole build. Each stage must then declare its own agent, which lets different stages run on different machines or containers and frees executors during input waits.
Can I import my current Jenkinsfile?
Yes, if it is declarative. Paste it in check mode and press Import into the form. Steps, when conditions, parallel branches and post actions are read back; nested stage groups stay as raw text.
Why are some stages greyed out in the stage view?
Their when condition does not match the branch or tag you typed in the simulator. Expressions cannot be evaluated here, so stages that depend on them are shown as running.
Does the tool connect to my Jenkins server?
No. It only writes and checks text in your browser. Nothing is sent to Jenkins or anywhere else.
