website
website copied to clipboard
Incorrect documentation for building and deploying a Go project
https://kubesphere.io/zh/docs/devops-user-guide/examples/go-project-pipeline/
Build the pipeline according to the steps in the document, when it is executed to the deploy app stage, the following error is reported:
Solution: remove the previous project name and it should be fine
Hi, the step in the document that you are referring to should be correct.
/cc @kubesphere/sig-devops Can you help look into this issue when you are available?
Yup, I confirmed that this sample was incorrect. Please see deploy.yaml. The correct one is deploy/git/go-projent/deploy.yaml
.
/cc @kubesphere/sig-devops Please correct me if I missed something.
Yup, I confirmed that this sample was incorrect. Please see deploy.yaml. The correct one is
deploy/git/go-projent/deploy.yaml
. /cc @kubesphere/sig-devops Please correct me if I missed something.
I ran the pipeline and it succeeded. 👀
If I use deploy/git/go-projent/deploy.yaml
, my pipeline failed. Did I do something wrong?
BTW, I think go-projent
should be updated to go-project
in the sample repository?
Hi, @luoMonkeyKing , please paste your Jenkinsfile into here.
嗨,@luoMonkeyKing,请将您的 Jenkinsfile 粘贴到此处。 Hi, here is my jenkinsfile, don't know if it's something wrong with what I wrote, I only pasted the stages part
stages {
stage('checkout scm') {
steps {
checkout(scm)
}
}
stage('build & push snapshot') {
steps {
container('go') {
sh 'docker build -t $DOCKER_REPO_ADDRESS/$DOCKER_REPO_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER -f DevopsDockerfile .'
withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$DOCKER_REPO_CREDENTIAL_ID" ,)]) {
sh 'echo "$DOCKER_PASSWORD" | docker login $DOCKER_REPO_ADDRESS -u "$DOCKER_USERNAME" --password-stdin'
sh 'docker push $DOCKER_REPO_ADDRESS/$DOCKER_REPO_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER '
}
}
}
}
stage('push latest'){
when{
branch 'branch'
}
steps{
container('go'){
sh 'docker tag $DOCKER_REPO_ADDRESS/$DOCKER_REPO_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $DOCKER_REPO_ADDRESS/$DOCKER_REPO_NAMESPACE/$APP_NAME:latest '
sh 'docker push $DOCKER_REPO_ADDRESS/$DOCKER_REPO_NAMESPACE/$APP_NAME:latest '
}
}
}
stage('deploy to dev') {
when{
branch 'branch'
}
steps {
container ('go') {
withCredentials([
kubeconfigFile(
credentialsId: env.KUBECONFIG_CREDENTIAL_ID,
variable: 'KUBECONFIG')
]) {
sh 'envsubst < deploy/dev/deploy.yaml | kubectl apply -f -'
}
}
}
}
stage('push with tag'){
when{
expression{
return params.TAG_NAME =~ /v.*/
}
}
steps {
container('go'){
input(id: 'release-image-with-tag', message: 'release image with tag?')
withCredentials([usernamePassword(credentialsId: "$GIT_CREDENTIAL_ID", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh 'git config --global user.email "[email protected]" '
sh 'git config --global user.name "huluoluo" '
sh "git tag -a ${params.TAG_NAME} -m \"${params.TAG_NAME}\" "
sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@$GIT_ADDRESS/$GIT_ACCOUNT/$APP_NAME.git --tags'
}
sh "docker tag $DOCKER_REPO_ADDRESS/$DOCKER_REPO_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $DOCKER_REPO_ADDRESS/$DOCKER_REPO_NAMESPACE/$APP_NAME:${params.TAG_NAME}"
sh "docker push $DOCKER_REPO_ADDRESS/$DOCKER_REPO_NAMESPACE/$APP_NAME:${params.TAG_NAME}"
}
}
}
stage('deploy to production') {
when{
expression{
return params.TAG_NAME =~ /v.*/
}
}
steps {
input(id: 'deploy-to-production', message: 'deploy to production?')
container ('go') {
withCredentials([
kubeconfigFile(
credentialsId: env.KUBECONFIG_CREDENTIAL_ID,
variable: 'KUBECONFIG')
]) {
sh 'envsubst < deploy/dev/deploy.yaml | kubectl apply -f -'
}
}
}
}
}