mirror of
https://github.com/appleboy/drone-jenkins.git
synced 2026-06-04 10:15:02 +08:00
3dd86f956c
- Add support for passing a remote trigger token to Jenkins jobs - Update the Jenkins constructor to accept a token parameter - Ensure the token is included as a query parameter when triggering jobs - Improve error reporting by including response body in error messages - Remove unnecessary logging and refactor build parameter logic - Update tests to use the new Jenkins constructor and token handling - Add CLI option for specifying a remote trigger token - Extend plugin configuration to support remote token injection Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
44 lines
1016 B
Go
44 lines
1016 B
Go
package main
|
|
|
|
import (
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestParseJobPath(t *testing.T) {
|
|
auth := &Auth{
|
|
Username: "appleboy",
|
|
Token: "1234",
|
|
}
|
|
jenkins := NewJenkins(auth, "http://example.com", "", false)
|
|
|
|
assert.Equal(t, "/job/foo", jenkins.parseJobPath("/foo/"))
|
|
assert.Equal(t, "/job/foo", jenkins.parseJobPath("foo/"))
|
|
assert.Equal(t, "/job/foo/job/bar", jenkins.parseJobPath("foo/bar"))
|
|
assert.Equal(t, "/job/foo/job/bar", jenkins.parseJobPath("foo///bar"))
|
|
}
|
|
|
|
func TestUnSupportProtocol(t *testing.T) {
|
|
auth := &Auth{
|
|
Username: "foo",
|
|
Token: "bar",
|
|
}
|
|
jenkins := NewJenkins(auth, "example.com", "", false)
|
|
|
|
err := jenkins.trigger("drone-jenkins", nil)
|
|
assert.NotNil(t, err)
|
|
}
|
|
|
|
func TestTriggerBuild(t *testing.T) {
|
|
auth := &Auth{
|
|
Username: "foo",
|
|
Token: "bar",
|
|
}
|
|
jenkins := NewJenkins(auth, "http://example.com", "remote-token", false)
|
|
|
|
err := jenkins.trigger("drone-jenkins", url.Values{"param": []string{"value"}})
|
|
assert.Nil(t, err)
|
|
}
|