What's the difference between Authentication Token and API Token in Jenkins remote build?

Viewed 1154

I'm trying to trigger Jenkins build from C#, using this link from here. I'm trying to invoke a paramaterised Jenkins Job from .NET.

In the Jenkins job, under the "Build Triggers' section, the "Trigger builds remotely (e.g., from scripts)" is checked and an authentication token is provided like this.

In my C# code, I'm asked to provide a username and an API token to invoke the Jenkins build. (_username, _apiToken from below)

 private static HttpWebRequest CreateHttpRequest(string URLName)
    {

        //Creating HTTP web request
        var httpWebRequest = (HttpWebRequest)WebRequest.Create(URLName);

        httpWebRequest.ContentType = "application/x-www-form-urlencoded";
        httpWebRequest.Method = "POST";

        byte[] credentialBuffer =
            new UTF8Encoding().GetBytes(
             _username + ":" +
            _apiToken);

        httpWebRequest.Headers["Authorization"] =
           "Basic " + Convert.ToBase64String(credentialBuffer);

        httpWebRequest.PreAuthenticate = true;
        return httpWebRequest;
    }

This API token, I get it from the Jenkins server by navigating to [Jenkins server URL]/me/configure and I provide this in my code.

Now, when I try to invoke this Jenkins job which has this remote build trigger enabled, I get Forbidden/Not found error via code. When I try to manually navigate that URl with the API token, it says invalid token. Could this be because of the 'Authentication Token' that I mentioned earlier?

I'm asking this, because if I uncheck that option and invoke the Jenkins Job from code, there is no issue at all.

1 Answers
Related