0
votes

For testing purposes I sometimes copy some Jenkins jobs from a produtive instance into our testing instance.

Repositories, branches etc. are controlled by environment variables but I want to block the "Deploy artifacts to Maven repository" post build action for all jobs in this Jenkins instance.

Any idea how to do this?

1

1 Answers

2
votes

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