elastic/opbeans-node

"Opbeans Node Bump" job fails with "You are not currently on a branch"

Closed this issue · 1 comments

Recent in #163 the code to handle running ".ci/bump-version.sh" and gitPush() etc. was moved from apm-agent-nodejs/.ci/Jenkinsfile to this repo (opbeans-node/.ci/bump-opbeans-node.groovy).

The failure was (https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-nodejs%2Fbump-opbeans-node-mbp/detail/main/2/pipeline):

git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/elastic/opbeans-node.git — Git push<1s

[2022-06-18T20:09:25.801Z] + git push https://****:****@github.com/elastic/opbeans-node.git
[2022-06-18T20:09:25.801Z] fatal: You are not currently on a branch.
[2022-06-18T20:09:25.801Z] To push the history leading to the current (detached HEAD)
[2022-06-18T20:09:25.801Z] state now, use
[2022-06-18T20:09:25.801Z] 
[2022-06-18T20:09:25.801Z]     git push https://****:****@github.com/elastic/opbeans-node.git HEAD:<name-of-remote-branch>
[2022-06-18T20:09:25.801Z] 
script returned exit code 128

details

elastic/apm-agent-nodejs#2764 removed support from apm-agent-nodejs.git. So before we had:

-        stage('Opbeans') {
-          environment {
-            REPO_NAME = "${OPBEANS_REPO}"
-          }
-          steps {
-            deleteDir()
-            dir("${OPBEANS_REPO}"){
-              git(credentialsId: 'f6c7695a-671e-4f4f-a331-acdce44ff9ba',
-                  url: "git@github.com:elastic/${OPBEANS_REPO}.git",
-                  branch: 'main')
-              // It's required to transform the tag value to the artifact version
-              sh script: ".ci/bump-version.sh ${env.BRANCH_NAME.replaceAll('^v', '')}", label: 'Bump version'
-              // The opbeans pipeline will trigger a release for the main branch
-              gitPush()
-              // The opbeans pipeline will trigger a release for the release tag
-              gitCreateTag(tag: "${env.BRANCH_NAME}")
-            }
-          }
-        }

and now we have:

+      steps {
+        withGithubNotify(context: 'Update Agent Dep') {
+          deleteDir()
+          gitCheckout(basedir: BASE_DIR)
+          dir(BASE_DIR){
+            script {
+              AVAIL_AGENT_UPDATE_VER = sh(
+                  script: '.ci/avail-agent-update-ver.sh',
+                  returnStdout: true
+              ).trim()
+              if (AVAIL_AGENT_UPDATE_VER) {
+                echo "Available agent version update: '${AVAIL_AGENT_UPDATE_VER}'"
+                sh(script: ".ci/bump-version.sh ${AVAIL_AGENT_UPDATE_VER}")
+                gitPush()
+                gitCreateTag(tag: "v${AVAIL_AGENT_UPDATE_VER}")
+              } else {
+                echo "This repo is already using the latest available APM agent version."
+              }
+            }
+          }
+        }

@v1v Do you think the fix might be to add credentialsId to the git checkout here:

gitCheckout(basedir: BASE_DIR)
? E.g. this:

diff --git a/.ci/bump-opbeans-node.groovy b/.ci/bump-opbeans-node.groovy
index d8ade27..60302ba 100644
--- a/.ci/bump-opbeans-node.groovy
+++ b/.ci/bump-opbeans-node.groovy
@@ -36,7 +36,9 @@ pipeline {
       steps {
         withGithubNotify(context: 'Update Agent Dep') {
           deleteDir()
-          gitCheckout(basedir: BASE_DIR)
+          gitCheckout(basedir: BASE_DIR,
+            credentialsId: 'f6c7695a-671e-4f4f-a331-acdce44ff9ba',
+            branch: 'main')
           dir(BASE_DIR){
             script {
               AVAIL_AGENT_UPDATE_VER = sh(
v1v commented

@v1v Do you think the fix might be to add credentialsId to the git checkout here:

I'd say to play safe to use the below command:

git(credentialsId: 'f6c7695a-671e-4f4f-a331-acdce44ff9ba',
     url: "git@github.com:elastic/${OPBEANS_REPO}.git",
     branch: 'main')

gitCheckout uses checkout that it's equivalent to git but since the above command worked fine in the past then I'd recommend to use it