Skip to content

Commit

Permalink
feat: use baseUrl from credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
saintsebastian committed Nov 11, 2021
1 parent aa64062 commit 7e1c170
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
6 changes: 6 additions & 0 deletions packages/nodes-base/nodes/Jenkins/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ export async function jenkinsApiRequest(this: IHookFunctions | IExecuteFunctions
throw new NodeApiError(this.getNode(), error);
}
}

export function tolerateTrailingSlash(baseUrl: string) {
return baseUrl.endsWith('/')
? baseUrl.substr(0, baseUrl.length - 1)
: baseUrl;
}
15 changes: 4 additions & 11 deletions packages/nodes-base/nodes/Jenkins/Jenkins.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {

import {
jenkinsApiRequest,
tolerateTrailingSlash
} from './GenericFunctions';

import {
Expand Down Expand Up @@ -50,15 +51,6 @@ export class Jenkins implements INodeType {
},
],
properties: [
{
displayName: 'Jenkins URL',
name: 'url',
type: 'string',
required: true,
default: '',
description: 'Location of Jenkins installation',
noDataExpression: true,
},
{
displayName: 'Resource',
name: 'resource',
Expand Down Expand Up @@ -427,6 +419,7 @@ export class Jenkins implements INodeType {
const { baseUrl, username, apiKey } = credential.data as JenkinsApiCredentials;
const token = Buffer.from(`${username}:${apiKey}`).toString('base64');

let const = tolerateTrailingSlash(baseUrl);
const endpoint = '/api/xml';

const options = {
Expand All @@ -436,7 +429,7 @@ export class Jenkins implements INodeType {
method: 'GET',
body: {},
qs: {},
uri: `${baseUrl}${endpoint}`,
uri: `${url}${endpoint}`,
json: true,
};

Expand Down Expand Up @@ -466,7 +459,7 @@ export class Jenkins implements INodeType {

for (let i = 0; i < length; i++) {
try {
const baseUrl = this.getNodeParameter('url', i) as string;
const { baseUrl } = await this.getCredentials('jenkinsApi') as JenkinsApiCredentials;
if (resource === 'job') {
if (operation === 'trigger') {
const token = this.getNodeParameter('token', i) as string;
Expand Down

0 comments on commit 7e1c170

Please sign in to comment.