Search code examples
gitjenkinsgroovyjenkins-pipelinejenkins-groovy

Can't get other scripts from my git repository, using Jenkinsfile


I think I have a childish problem, but I can't find any solution by myself.

I have a Jenkins-pipeline which works using a Jenkinsfile.groovy from git-repo (Bitbucket).

This git-repo has some python scripts which I try to run in stages of the Jenkinsfile.

And I just get "[Errno 2] No such file or directory" for every python script.

I thought that every run of the pipeline makes a cloned directory or smth with all scripts of the git-repo, so I can use a relative path for scripts for run them in the stages.

But it doesn't work this way, or I just don't understand how to set the right way to python scripts.

For example: link to git-repo: ssh://git@testrepo:7999/myproject/jenkins_scripts.git path to jenkinsfile: test-pipeline/Jenkinsfile.groovy

How should I run the python scripts from the Jenkinsfile?

How should I set the path for this type of scripts?

Now I have a really stupid solution - it's just cloning the git-repo and setting the absolute paths to python scripts in the Jenkinsfile.

But I thinks it just shouldn't work this way.


Solution

  • If you have set the option "Lightweight checkout", then there will not be a full checkout:

    If selected, try to obtain the Pipeline script contents directly from the SCM without performing a full checkout.

    This is done so that the pipeline can run without having to checkout the whole repo. Turn this off if you want everything to be checked out.

    There is also the case that you are simply in the wrong directory when trying to run the Python script. However, I cannot say this for sure since you have not provided any code of your Jenkins file. But essentially, this should work:

    dir("path/to/python/scripts") {
       // Run Python file
    }
    

    You can also use the $WORKSPACE inbuilt variable to access the workspace where the repo is being cloned.