Closed jstrachan closed 7 years ago
At a minimum, we should block the import if we find a pre-existing Jenkinsfile and the user does NOT want his file replaced.
in pseudo-code we should add a CheckExistingJenkinsfileStep
to the fabric8-generator before the ChoosePipelineStep
.
CheckExistingJenkinsfileStep.initialise()
would check if there's an existing Jenkinsfile in the project(s) being processed (using the same code as ChoosePipelineStep
to figure out if there's a Jenkinsfile in any project). If there is add an UIInput<Boolean> keepJenkinsfiles
input in initialise() to the builder as to whether to overwrite the jenkinsfile or not (defaulting to false I guess)? If not found we don't add that input so that this wizard step becomes invisible. keepJenkinsfiles
property is rendered to describe how we recommend overwriting any existing Jenkinsfiles (and that folks can always revert to the previous values in git if they want), but our curated Jenkinsfiles are recommended etc).CheckExistingJenkinsfileStep.execute()
would then check if keepJenkinsfiles.getValue() is true and if so set an attributeMap value of 'keepJenkinsfiles' to trueChoosePipelineStep.initialise
would check for the attributeMap value ofkeepJenkinsfiles
and if enabled it'd not show the pipeline
input in the UI (which would effectively skip that UI page on the client side UI)ChoosePipelineStep.execute
should then deal with no Jenkinsfile being chosen - so it'd not overwrite a Jenkinsfile if none was selected - but still do the other source code swizzling (like pom / che stuff) - I think that should work right now anyways - just needs some testingMaybe a much simpler way to implement it is to detect an existing Jenkinsfile exists in ChoosePipelineStep
and add an UIInput<Boolean> keepJenkinsfile
option to it first? If the user opts to keep jenkinsfiles then any project(s) being imported/created will not use the selected pipeline but will reuse the existing one - otherwise it carries on as normal copying the selected Jenkinsfile into the project(s).
The only complication is we can import multiple projects; so if there are multiple projects being imported; one could have a Jenkinsfile, another may not. So if we take this approach we probably always want to show the pick pipeline UI - even if the user selects the 'keepJenkinsfile' option (so that the pipeline selection is ignored).
Am not sure thats such a big issue really; the main thing is we let users opt out of replacing Jenkinsfiles if they are present (but overwrite them by default and give a suitable warning)?
Then we can always revisit again later if we can figure out a better UX?
its fairly likely that old versions will work worse than the curated version; but we could allow users to opt out of the upgrade on import