Permission denied error - jenkins (shell script)

℡╲_俬逩灬. 提交于 2021-01-23 05:33:14

问题


I'm using a jenkinsfile to test one of our instances. For this I created a bash script. Problem is that jenkins doesn't have permissions to run the script. Any idea how to fix this?

Jenkinsfile:

 stage("Testing instances"){
    if (terragruntAction == 'apply' || terragruntAction == 'test'){
       echo "Testing"
       sh '../check_services.sh'
    }
 }

output:

../check_services.sh: Permission denied

I tried to do:

git update-index --chmod=+x check_services.sh 

on the git folder that gets checkouted by Jenkins but no luck.

Any help, thanks in advance!


回答1:


I got it working with adding this to the GIT repo: git update-index --chmod=+x check_services.sh




回答2:


My preference is to keep access permissions for individual files out of my git repo, favoring a method to handle this right inside the pipeline instead. Simply run the chmod ahead of the execution of the script, to give permissions to the workspace. Using declarative:

    stage('My Stage') {
        steps {
            sh "chmod +x -R ${env.WORKSPACE}"
            sh "./my-script.sh"
        }
    }

NOTE: For those who don't know this yet, the other requirement is to explicitly tell pipeline where the script is relative to the workspace. Just using sh "my-script.sh" won't work.



来源:https://stackoverflow.com/questions/46766121/permission-denied-error-jenkins-shell-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!