0

I have a stage in my pipeline like below:

stage("Pre Flight Checks") {
            steps {
                echo 'using the message count externally'
                script {
                    // Execute the shell command and assign the result to an environment variable
                    def messageCount = sh(script: "git rev-list origin/${env.DEV_BRANCH_NAME}..origin/${env.BRANCH_NAME} --oneline | wc -l", returnStdout: true).trim()
                    env.message_count = messageCount
                }
                echo "message_count: ${env.message_count}"
                preFlightChecks()
            }
        }

I have defined few validations in my dsl lib function preFlightChecks() to run some checks. Here is the problem i am getting:

13:35:52  + git rev-list origin/develop..origin/release_10122024_1 --oneline
13:35:52  fatal: ambiguous argument 'origin/develop..origin/release_10122024_1': unknown revision or path not in the working tree.
13:35:52  Use '--' to separate paths from revisions, like this:
13:35:52  'git <command> [<revision>...] -- [<file>...]'
13:35:52  + wc -l

I am trying to identify the number of commit differences between the 2 branches and parse the logic based on that value.

while the same command works fine when i am running locally. works intermittently over the CI. How to understand this behaviour? i am clueless !! dear experts please provide your inputs.

6
  • 1
    Let me guess: working on a shallow clone?
    – eftshift0
    Commented Dec 10, 2024 at 13:42
  • No @eftshift0. i am using advanced clone behaviour only for fetch tags.No shallow clone. Commented Dec 10, 2024 at 14:10
  • OK.... let's play safe... can you run this in the pipeline before doing that failing command? git rev-parse origin/develop and git rev-parse origin/release_10122024_1? If you get 2 IDs out of that (which would be quite a shocker), let us know.
    – eftshift0
    Commented Dec 10, 2024 at 15:11
  • And... you are fetching before trying to run that, right?
    – eftshift0
    Commented Dec 10, 2024 at 15:12
  • yes @eftshift0 . i am fetching it before for sure :). I got 2 different IDs out of that, which is expected. but now a followup step is throwing error. ** 15:08:52 + git rev-parse HEAD~1 15:08:52 fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree. 15:08:52 Use '--' to separate paths from revisions, like this: 15:08:52 'git <command> [<revision>...] -- [<file>...]' 15:08:52 HEAD~1 ** This happened on the same run. This is the main concerning thing. The git commands are behaving so flaky way. Commented Dec 11, 2024 at 15:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.