Hi,
I’m working on a project about Jenkins pipeline but after last stage i’ve an error "failed to initialize build cache at /.cache/go-build: mkdir /.cache: permission denied"
Please help
My Jenkinsfile
#!/usr/bin/env groovy
// The above line is used to trigger correct syntax highlighting.
pipeline {
agent any
stages {
stage('Build & Test') {
// Use golang.
agent { docker { image 'golang' } }
steps {
// Create our project directory.
sh 'cd ${GOPATH}/src'
sh 'mkdir -p ${GOPATH}/src/PROJECT_DEVOPS'
// Copy all files in our Jenkins workspace to our project directory.
sh 'cp -r ${WORKSPACE}/* ${GOPATH}/src/PROJECT_DEVOPS'
// Build the app.
sh 'go build'
}
}
}
My first guess is that the Jenkins worker runs in an environment that has neither XDG_CACHE_DIR, nor HOME set, so as XDG isn’t set, $HOME/.cache is used as fallback, though as HOME isn’t set as well, it expands to /.cache where usually no one’s has write access.
Though this is just an assumption based on XDG spec.
This isn’t an exact answer but hopefully helps… You have at least two options. One is to set GOCACHE="${WORKSPACE}" (the Jenkins name for your per-build writable area). You used to be able to say GOCACHE=off but can’t since 1.12.
You might also benefit from using dir(), something like: