0
0
Jenkinsdevops~5 mins

Avoiding hard-coded values in Jenkins - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does 'avoiding hard-coded values' mean in Jenkins pipelines?
It means not writing fixed values directly in the pipeline script. Instead, use variables or parameters so you can change values without editing the code.
Click to reveal answer
beginner
Why should you avoid hard-coded values in Jenkins pipelines?
Because hard-coded values make scripts less flexible and harder to maintain. Using variables or parameters helps reuse the pipeline for different projects or environments easily.
Click to reveal answer
intermediate
How can you pass values to a Jenkins pipeline without hard-coding?
You can use parameters in the pipeline, environment variables, or external configuration files to pass values dynamically.
Click to reveal answer
beginner
Example: How to define a string parameter in a Jenkins declarative pipeline?
Use the parameters block like this:<br>
parameters {
  string(name: 'BRANCH_NAME', defaultValue: 'main', description: 'Git branch to build')
}
Click to reveal answer
intermediate
What is the benefit of using environment variables in Jenkins pipelines?
Environment variables let you store values outside the code and reuse them in multiple places. This avoids repeating hard-coded values and makes updates easier.
Click to reveal answer
Which method helps avoid hard-coded values in Jenkins pipelines?
AUsing parameters and environment variables
BWriting fixed values directly in the script
CCopy-pasting the same value multiple times
DIgnoring configuration files
How do you define a string parameter in a Jenkins declarative pipeline?
Aenv { PARAM = 'value' }
Bparameters { string(name: 'PARAM', defaultValue: 'value', description: 'desc') }
Cstage('Param') { steps { echo 'value' } }
Dnode { param('PARAM') }
What is a risk of hard-coding values in Jenkins pipelines?
AParameters are automatically created
BPipelines run faster
CScripts become less flexible and harder to update
DEnvironment variables are ignored
Which of these is NOT a way to avoid hard-coded values?
AWriting fixed values directly in the script
BUsing pipeline parameters
CUsing environment variables
DUsing external configuration files
What does the 'environment' block in Jenkins pipeline do?
ARuns shell commands
BSets pipeline parameters
CDeclares pipeline stages
DDefines environment variables for the pipeline
Explain why avoiding hard-coded values is important in Jenkins pipelines and how you can implement it.
Think about how changing values without editing code helps.
You got /4 concepts.
    Describe how to define and use a string parameter in a Jenkins declarative pipeline.
    Look for the parameters { string(...) } syntax.
    You got /3 concepts.