how to remove files from my server with pipeline script to remove all files except 5 using ssh

Viewed 20

pipeline script which is throwing error

hided ip and name for security

INPUT that i gave for the jenkins pipeline script :

sh ["""ssh -T -o StrictHostKeyChecking=no myname@myip sh yes | rm -v /home/user/usr/share/nginx/html!("api"|"inpinn"|"outpinn"|"hp_frontend"|"email_inpinn")""")]

OUTPUT in Jenkins :

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 15: Expected a step @ line 15, column 13. sh [("""ssh -T -o StrictHostKeyChecking=no MYname@myIP sh yes | rm -v /home/user/usr/share/nginx/html!("api"|"inpinn"|"outpinn"|"hp_frontend"|"email_inpinn")""")] ^

1 error

at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:309)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1107)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:624)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:602)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:579)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:323)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:293)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:677)
at groovy.lang.GroovyShell.parse(GroovyShell.java:689)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:561)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:513)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:335)
at hudson.model.ResourceController.execute(ResourceController.java:107)
at hudson.model.Executor.run(Executor.java:449)

[withMaven] downstreamPipelineTriggerRunListener - Failure to introspect build steps: java.io.IOException: testssh #142 did not yet start [withMaven] downstreamPipelineTriggerRunListener - Failure to introspect build steps: java.io.IOException: testssh #142 did not yet start Finished: FAILURE

1 Answers

I guess you haven't surrounded it with: script { ssh( .. ) } and I'm not sure if square brackets will work (use parentheses) for ssh.

Related