Comments (2)
Anyone know?
from vsts-extension-samples.
Fancy finding you here as well, @patricknolan
It would be good to add this as an example if one does not exist quite yet, but to use a connected service, you can do the following (copied from my own SO answer in case the internet breaks):
The trick is to use some more functions from azure-pipelines-task-lib/task
(in your case, tl
):
If your custom Connected Service adds an authentication scheme of type ms.vss-endpoint.endpoint-auth-scheme-token
, then the id
of the token input would be apitoken
, and the code you would need to add would look something like the following:
const endpoint = tl.getEndpointUrl(serviceString, true);
// The second parameter here is the name of the associated input
// value(s) of the specific authenticationSchemes type (more on that later).
const token = tl.getEndpointAuthorizationParameter(serviceString, "apitoken", false)
How do I know this? Experimentation.
Other Authentication Types
My current experience echoes that of others' from the past: Azure DevOps does not play nicely with fully custom Connected Services. It does ship with a few that cover most bases. Depending on which one(s) you use, the value you pass for the second parameter of tl.getEndpointAuthorizationParameter
changes:
ms.vss-endpoint.endpoint-auth-scheme-token
Ships with one standard input:
apitoken
ms.vss-endpoint.endpoint-auth-scheme-basic
Ships with two inputs:
username
password
Example Plus Suggestion
Suggestion first: to make your code clearer, rename your serviceString
variable to connectedServiceId
(or some variation to be clear that is represents the ID of your connected service).
import tl = require('azure-pipelines-task-lib/task');
async function run() {
try {
const connectedServiceId = tl.getInput('TestService', true);
if (connectedServiceId == 'bad' || connectedServiceId == undefined) {
tl.setResult(tl.TaskResult.Failed, 'Bad input was given');
return;
}
const endpoint = tl.getEndpointUrl(connectedServiceId, true);
const token = tl.getEndpointAuthorizationParameter(connectedServiceId, "apitoken", false)
}
finally {
// Probably report some failure here, right?
}
}
Additionally, adding the connectedServiceId == undefined
check allows for safe usage of connectedServiceId
in later function calls.
Examples I found helpful/created
from vsts-extension-samples.
Related Issues (20)
- Is there any way to test dashboard widgets extension locally HOT 1
- Develop own widget on dashboard view
- Grid not showing data in IE11 nor Edge HOT 1
- build-results-enhancer not showing data in IE11 nor Edge HOT 2
- LightboxOptions code in widget
- Getting error while compiling Types Script
- No emails from data-storage notifications
- Build Results Enhancer no longer works HOT 2
- Missing Repository creation extension point
- Is it possible to register to workitem change event in backlogs panel extension?
- An undefined error occurred while attempting to connect to the server. Status code 0:
- Current Repository in Web Context
- Pull Request Status Menu for policy regardless of genre
- How to get build id from ms.vss-build-web.build-results-tab HOT 1
- How to get workItems in ms.vss-dashboards-web.widget-configuration
- Callback with workitem Id from new workitem window
- VSTS Extension - How to get selected suite data from test suites table on loading of custom tab HOT 1
- This repo is missing important files HOT 4
- Is this project still maintained?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vsts-extension-samples.