There is a Jenkins plugin for conditional build steps: Conditional Build Step Plugin. While plugin supports a variety of condition types, for reference here simple use of toggling deployment via global Jenkins property used in a boolean condition.
Property can be defined as Global Property in Jenkins configuration (Jenkins home > Manage > Configure: Global Properties)
As example lets say you have defined a property with name doMavenDeploy
:
- production environment: property value is
true
- test environment: property value is
false
job configuration would need to be modified to add a Conditional build step with :
- Run? : Boolean condition
- Token :
$doMavenDeploy
- Step to run if condition is met : add maven deployment there.
In that way you would need to modify your jobs once, after modified configuration is active you can move them between both servers without impacts.
There are other alternatives possible depending on specifics and constraints in your projects:
- introduce different maven profiles for 'normal' and test builds and control activation via environment variable, file present or similar
- if you use artifactory/nexus or similar: configure test server without deployer credentials