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

No GitHub configuration available for this job

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Trivial Trivial
    • github-issues-plugin
    • None
    • Linux

       I have configured GitHub server, as well as GitHub username and password in my, configure system options. I even configured the GitHub project in Jenkins job. But I am still getting
      WARNING: No GitHub config available for this job, GitHub Issue Notifier will not run! Error: Could not connect to GitHub repository. Please double-check that you have correctly configured a GitHub API key.. Can someone help me out on how should I resolve this issue.

          [JENKINS-46734] No GitHub configuration available for this job

          I had a breakthrough this morning.

           

          Something funky goes on with Jenkinsfiles/multi-branch builds. I am forcing a configuration and specifying credentials manually. I also needed to generate an HTTPS URL string without the .git ending for a successful connection. 

           

          Before I file the issue, I call a function to setup the configuration. This takes a token ID as input.

           

          ```

          def call(String credentialsID = 'github-oauth-token')
          {
          repoUrl = gitRepoHttpsUrl()

          echo "Creating a GitHubPluginConfig for credential $credentialsID"
          // configure github plugin
          GitHubPluginConfig pluginConfig = GitHubPlugin.configuration()
          GitHubServerConfig serverConfig = new GitHubServerConfig(credentialsID)
          pluginConfig.setConfigs([serverConfig])
          pluginConfig.save()

          echo "Registering GithubProjectProperty for repo URL $repoUrl"
          // Set a project property for the Github URL
          properties([[$class: 'GithubProjectProperty', projectUrlStr: repoUrl]])
          }

          ```

          Here's the HTTPS URL generation function:

           

          ```

          def call()
          {
          sh "git config --get remote.origin.url > .git/remote-url"
          url = readFile(".git/remote-url").trim()

          if(url.startsWith('git@'))
          {
          url = url - 'git@'
          url = 'https://' + url
          }

          if(url.endsWith('.git'))
          {
          url = url - '.git'
          }

          return url
          }

          ```

           

          Then I call the issue notifier:

           

          ```

          def call(String title = null, String label = null)
          {
          echo 'Build failed! Filing GitHub issue'

          step([$class: 'GitHubIssueNotifier',
          issueAppend: true,
          issueLabel: '',
          issueTitle: "${env.JOB_NAME}: Build failure"])

          //$BUILD_DISPLAY_NAME failed'])
          }

          ```

           

          Using these steps, I have successfully created an issue in the Github repo when a build fails.

          Phillip Johnston added a comment - I had a breakthrough this morning.   Something funky goes on with Jenkinsfiles/multi-branch builds. I am forcing a configuration and specifying credentials manually. I also needed to generate an HTTPS URL string without the .git ending for a successful connection.    Before I file the issue, I call a function to setup the configuration. This takes a token ID as input.   ``` def call(String credentialsID = 'github-oauth-token') { repoUrl = gitRepoHttpsUrl() echo "Creating a GitHubPluginConfig for credential $credentialsID" // configure github plugin GitHubPluginConfig pluginConfig = GitHubPlugin.configuration() GitHubServerConfig serverConfig = new GitHubServerConfig(credentialsID) pluginConfig.setConfigs( [serverConfig] ) pluginConfig.save() echo "Registering GithubProjectProperty for repo URL $repoUrl" // Set a project property for the Github URL properties([ [$class: 'GithubProjectProperty', projectUrlStr: repoUrl] ]) } ``` Here's the HTTPS URL generation function:   ``` def call() { sh "git config --get remote.origin.url > .git/remote-url" url = readFile(".git/remote-url").trim() if(url.startsWith('git@')) { url = url - 'git@' url = 'https://' + url } if(url.endsWith('.git')) { url = url - '.git' } return url } ```   Then I call the issue notifier:   ``` def call(String title = null, String label = null) { echo 'Build failed! Filing GitHub issue' step([$class: 'GitHubIssueNotifier', issueAppend: true, issueLabel: '', issueTitle: "${env.JOB_NAME}: Build failure"]) //$BUILD_DISPLAY_NAME failed']) } ```   Using these steps, I have successfully created an issue in the Github repo when a build fails.

          I normally write firmware in C/C++, so I'm not sure where the problem stems from in the underlying Java code

          Phillip Johnston added a comment - I normally write firmware in C/C++, so I'm not sure where the problem stems from in the underlying Java code

          Can you confirm that the credentials are configured correctly? Here's how it should look in your Jenkins config:

          Notably:

          1. Something should be selected in the "Credentials" dropdown
          2. The "Test connection" button should work

          I don't know a lot about pipelines so they might require separate configuration.

          Daniel Lo Nigro added a comment - Can you confirm that the credentials are configured correctly? Here's how it should look in your Jenkins config: Notably: Something should be selected in the "Credentials" dropdown The "Test connection" button should work I don't know a lot about pipelines so they might require separate configuration.

          In my setup I do have that configured, as other plugins require it to function correctly. I think the root cause for me is that the credentials aren't actually being picked up by the plugin. It works once I force a config with specific credentials via the first function I supplied.

          Does your plugin only load the `github-oath-token` credentials ID?

          Phillip Johnston added a comment - In my setup I do have that configured, as other plugins require it to function correctly. I think the root cause for me is that the credentials aren't actually being picked up by the plugin. It works once I force a config with specific credentials via the first function I supplied. Does your plugin only load the `github-oath-token` credentials ID?

          Daniel Lo Nigro added a comment - This plugin uses the GitHub plugin to find the credentials to use: https://github.com/jenkinsci/github-issues-plugin/blob/31dca10e324e6fbd0c7cab0b422b387263f32329/src/main/java/org/jenkinsci/plugins/githubissues/GitHubIssueNotifier.java#L110-L117 https://github.com/jenkinsci/github-plugin/blob/master/src/main/java/com/cloudbees/jenkins/GitHubRepositoryName.java#L141  

          Phani Kumar added a comment -

          Yes daniel15, I have configured the credentials properly. Even the test connection was successful. But I am getting the error as mentioned above.

          Phani Kumar added a comment - Yes daniel15 , I have configured the credentials properly. Even the test connection was successful. But I am getting the error as mentioned above.

          Same in my case.

          Phillip Johnston added a comment - Same in my case.

          Saul Cruz added a comment - - edited

          same issue here. using a very basic freestyle job. Github server is configured and the test connection works! any ideas? I'm using SSH authentication within my build job

          Saul Cruz added a comment - - edited same issue here. using a very basic freestyle job. Github server is configured and the test connection works! any ideas? I'm using SSH authentication within my build job

          Lisa Waugh added a comment -

          I have this issue also.  I have configured everything that I've been shown but still no luck.

           

          Could you provide additional assistance?

           

           

          Lisa Waugh added a comment - I have this issue also.  I have configured everything that I've been shown but still no luck.   Could you provide additional assistance?    

          The API token you use from Jenkins must have enough permissions on GitHub https://github.com/settings/tokens

           

          Aleksandr Lanin added a comment - The API token you use from Jenkins must have enough permissions on GitHub https://github.com/settings/tokens  

            daniel15 Daniel Lo Nigro
            phani_kumar Phani Kumar
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: