Jenkins

詹金斯建構錯誤:沒有這樣的文件或目錄

  • April 17, 2017

我的問題:當我使用 jenkins 建構時,我收到沒有這樣的文件的錯誤。但是那個文件是存在的。

jenkins@ip-172-31-22-20:~/jobs$ ls -lthr /var/lib/jenkins/jobs/github-commit-status-api/builds/43/build.xml
-rw-r--r-- 1 jenkins jenkins 2.5K Mar 23 08:13 /var/lib/jenkins/jobs/github-commit-status-api/builds/43/build.xml
jenkins@ip-172-31-22-20:~/jobs$

我的錯誤:

cat: /var/lib/jenkins/jobs/github-commit-status-api/builds/43/build.xml: No such file or directory

我來自 Jenkins 儀表板的建構後操作:

postsuccess()
{
 cat <<EOF
{  
   "state": "success",
   "target_url": "https://github.com/HSarode-Compumatrice/money-1",
   "description": "The build succeeded!",
   "context": "continuous-integration/jenkins"
}
EOF
}
postfailure()
{
 cat <<EOF
{  
   "state": "failure",
   "target_url": "https://github.com/HSarode-Compumatrice/money-1",
   "description": "Build Failure!",
   "context": "continuous-integration/jenkins"
}
EOF
}







echo "$BUILD_NUMBER"
BUILD_STATUS=`sudo cat /var/lib/jenkins/jobs/github-commit-status-api/builds/$BUILD_NUMBER/build.xml | grep -oP '(?<=<result>).*?(?=</result>)'`
echo $BUILD_STATUS 

if [ "$BUILD_STATUS" = "SUCCESS" ]
then
`curl -X POST -H "Authorization: Basic f69a042ad72594792950fecc8ca4539d2fff7b75" -H "Content-Type: application/json" 
-d  "$(postsuccess)" "https://api.github.com/repos/HSarode-Compumatrice/money-1/statuses/$GIT_COMMIT"` 
else
#`curl -X POST -H "Authorization: Basic f69a042ad72594792950fecc8ca4539d2fff7b75" -H "Content-Type: application/json" 
#-d  "$(postfailure)" "https://api.github.com/repos/HSarode-Compumatrice/money-1/statuses/$GIT_COMMIT"` 
echo "In Failed"
fi

詹金斯控制台輸出:

Started by user Harshal Sarode
[EnvInject] - Loading node environment variables.
Building on master in workspace /var/lib/jenkins/workspace/github-commit-status-api
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/HSarode-Compumatrice/money-1.git # timeout=10
Fetching upstream changes from https://github.com/HSarode-Compumatrice/money-1.git
> git --version # timeout=10
using GIT_ASKPASS to set credentials 
> git fetch --tags --progress https://github.com/HSarode-Compumatrice/money-1.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision b159d0e0d0f71f3d1e399c877705c9d698cd9e14 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f b159d0e0d0f71f3d1e399c877705c9d698cd9e14
> git rev-list b159d0e0d0f71f3d1e399c877705c9d698cd9e14 # timeout=10
[github-commit-status-api] $ /bin/bash -xe /tmp/jenkins5873807540526862643.sh
+ echo 'Before Building!!'
Before Building!!
[PostBuildScript] - Execution post build scripts.
[github-commit-status-api] $ /bin/bash -xe /tmp/jenkins982148387285704643.sh
+ echo 43
43
++ sudo cat /var/lib/jenkins/jobs/github-commit-status-api/builds/43/build.xml
++ grep -oP '(?<=<result>).*?(?=</result>)'
cat: /var/lib/jenkins/jobs/github-commit-status-api/builds/43/build.xml: No such file or directory
+ BUILD_STATUS=
Build step 'Execute a set of scripts' changed build result to FAILURE
Build step 'Execute a set of scripts' marked build as failure
Finished: FAILURE

/var/lib/jenkins/jobs/github-commit-status-api/builds/<build number>如果您在建構過程中進入該文件夾,您會看到該文件夾build.xml不存在,並且在建構完成之前不會存在。

引用自:https://serverfault.com/questions/840084