I am creating a recipe which reads the jenkinsfile and update the content back the jenkinsfile I created a java class which extends Recipe and overrided the getVistor method from Recipe and tried to implement the logic inside the visitor method but even before reaching inside the visitor i am receiving below error
Here is my code
public class testRecipe extends Recipe { @Override public TreeVisitor\<?, ExecutionContext\> getVisitor(){ return PreConditions.chek(new FindSourceFiles("jenkinsfile"), new GroovyVisitor\<\>()){ @Override public G.CompilationUnit visitCompilationUnit(G.CompilationUnit cu, ExecutionContext ctx){ //code to get the statements and update the statement } )}; } }
There were problems parsing JenkinsFIle [WARNING] org.openrewrite.groovy.GroovyParsingException: Failed to pasre Jenkinsfile at cursor position 1461. The next 10 characters in the original sourec are '{ ' org.openrewrite.groovy.GroovyParserVisitor.visit(GroovyParserVisitor.java:174)
If I add simple content in jenkins file it works below is working yml
#!groovy? @Library('Library@version')\_ def buildPipeline(){ pipelinerunner{ yml= 'test.yml' } }
This is not working
#!groovy? @Library('Library@version')\_ def buildPipeline(){ pipelinerunner{ yml= 'test.yml' } } def buildPipeline2(){ pipelinerunner{ yml= 'test4.yml' } }
Does anyone know if I am using the right visitor? Is there any visitor I should use to read the jenkins file? My jenkins file doesn't have any file extension it's simple a File type.
Appreciate if anyone can point me in the right direction