Typical Pipeline Structure
A declarative Jenkinsfile usually follows this pattern:- Source: Checkout code from GitHub, Bitbucket, etc.
- Build: Compile, build, and package your application.
- Test: Execute unit tests, integration tests, and other suites.
- Deploy: Push artifacts to staging or production environments.
Key Declarative Directives
environment Directive
Set environment variables globally or override them per-stage:post Directive
Define actions to run after the entire pipeline finishes, based on the outcome:script Directive
Usescript blocks to include complex Groovy logic:
Use
script sparingly. Most tasks can be handled with declarative steps or existing plugins.when Directive
Control stage execution based on conditions (branches, environment, tags):credentials Directive
Inject Jenkins-managed credentials securely:Never print credentials or secrets to the console. Always use the Jenkins credentials store and the appropriate binding methods.