Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-71837

Some time API call failed while call createContent method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • github-api-plugin
    • None
    • Production

      Hello Team,

      I am using that API for download file from Github repository then update file content then push that file. Created Jenkins library and call the function from Jenkins job.  

      Following are the code that using for get file then update and push.  

       

      def repository = new GithubBuilder()
              .build(githubCredential)
              .getRepository(pullRequestInfo.repositoryFullName)
      
      GHContent ghContent = repository.getFileContent(filePath, pullRequestInfo.branchName)
      
      if(!repository.branches.find { Map.Entry entry -> entry.key == pullRequestInfo.branchName}) {
          echo "branch ${pullRequestInfo.branchName} DOES NOT exist"
          log.info("Branch ${pullRequestInfo.branchName} does not exist")
      } else {
          echo "branch ${pullRequestInfo.branchName} exist"
          log.info("Using branch ${pullRequestInfo.branchName}")
          repository.createContent()
                  .path(ghContent.path)
                  .content(fileContent)
                  .branch(pullRequestInfo.branchName)
                  .message(commitMessage)
                  .sha(ghContent.sha)
                  .commit()
      
          log.info("File ${ghContent.path} updated on branch ${pullRequestInfo.branchName}")
      } 

       

       

      But some time it's failed with following error. 

      hudson.remoting.ProxyException: org.kohsuke.github.HttpException: {"message":"xxxxx/xxxxxx/terraform.tfvars does not match de388744f1563ba424e35610156bdda5aef2a8b5","documentation_url":"https://docs.github.com/rest/repos/contents#create-or-update-file-contents"} at org.kohsuke.github.GitHubConnectorResponseErrorHandler$1.onError(GitHubConnectorResponseErrorHandler.java:56) at org.kohsuke.github.GitHubClient.detectKnownErrors(GitHubClient.java:424) ...
      ...
      ....
      Could not update commit status. Message: {"message":"Validation Failed","errors":[{"resource":"Status","code":"custom","message":"This SHA and context has reached the maximum number of statuses."}],"documentation_url":"https://docs.github.com/rest/commits/statuses#create-a-commit-status"} 

      Could you please help me what there is wrong. Following are the versions that I am using.

      github-api - 1.301-378.v9807bd746da5
      org.kohsuke - 1.301


      Thanks
      Ravi

            Unassigned Unassigned
            ravi057 Ravi
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: