7

I'm creating a jenkins pipeline. We have a bash script which need to be executed but which is not in the repository itself.

How do I have to execute this script? I tried:

  • configFileProvider: use the configFileProvider to get the script in a variable. The execution did not work and I'm also thinking this is not the way to do it? This is meant for config files and not real scripts?

  • I have a shared library which contains resources/. From here I've copied the script and executed it with sh after copying the content in a file.. This went well but I have the script in my workspace which I do not prefer. I want to execute commands on my workspace but when I perform git commit's etc. I don't want the file to be in my workspace if that's possible.

What is the right way to execute a managed script (from managed scripts or from in git) in my jenkins pipeline?

Without pipelines I use: Managed scripts. When I execute it I see in the logs:

executing script 'test-xxx.sh'
[test-xxx] $ /bin/bash /tmp/build_step_template3284004xxx.sh param1 param2 param3

This is the ideal solution I want to replicate in Jenkins pipelines. My script which is NOT in my workspace but is executed on my workspace and is temporary.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
DenCowboy
  • 13,884
  • 38
  • 114
  • 210
  • This may help using Pipeline Shared Libraries to store non-Groovy code, https://stackoverflow.com/questions/40213654/how-to-invoke-bash-functions-defined-in-a-resource-file-from-a-jenkins-pipeline – dragon788 May 01 '18 at 22:54

1 Answers1

0

I used to use the Scriptler plugin, however it had security issues raised against it.

When I moved all my stuff from freestyle builds to pipelines (expressed in Groovy) in 2017/8 I migrated that functionality to Shared Libraries (as an aside: right place to put code that runs against the Jenkins object model).

All paths in a Jenkins job (freestyle or pipeline) are %JENKINS_WORKSPACE% relative. Jenkins does not natively like you going above this directory on the filesystem.

I would highly recommend all the stuff your build process needs be in the primary Jenkins workspace (preferably via a git checkout or a shared library). Versioning everything in git will always be your friend. If this is not what you want to do, other options could be:

  1. Shared Workspace
  2. This post
Andrew Gray
  • 3,593
  • 3
  • 35
  • 62