tag:help.appveyor.com,2012-11-13:/discussions/questions/305-trigger-a-buildAppVeyor: Discussion 2018-08-25T02:00:31Ztag:help.appveyor.com,2012-11-13:Comment/332207952014-06-02T03:05:19Z2014-06-02T03:05:19ZTrigger a Build<div><p>Hi Matt,</p>
<p>Yes, you can use API to start a new build. Check this page for
code examples calling API: <a href=
"http://www.appveyor.com/docs/api">http://www.appveyor.com/docs/api</a></p>
<p>To start a new build call the following URL:</p>
<pre>
<code>POST https://ci.appveyor.com/api/builds</code>
</pre>
<p>with body:</p>
<pre>
<code>{
"accountName": "<your-account>",
"projectSlug": "<project-slug-from-URL>",
"branch": "<optional-branch-name>"
}</code>
</pre></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/332207952014-06-02T03:07:50Z2014-06-02T03:07:50ZTrigger a Build<div><p>In general, you can use Chrome developer tools or Fiddler to see
what's being called on API. AppVeyor UI uses API only.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/332207952014-07-04T08:50:02Z2014-07-04T08:50:04ZTrigger a Build<div><p>I've been strugging getting this working</p>
<p>I have in powershell</p>
<p>`$token = 'token'</p>
<p>$headers = @{ "Authorization" = "Bearer $token"}</p>
<p>$body = @{accountName = "accountName"; projectSlug =
"pslug"}</p>
<p>$bodyAsJson = $body | ConvertTo-json`</p>
<p><code>Invoke-Restmethod -uri
'https://ci.appveyor.com/api/builds' -Headers $headers -Method Post
-Body $bodyAsJson</code></p>
<p>And I get back<br>
<code>{"message":"Project not found or access denied."}</code></p>
<p>However by accident I entered</p>
<p><code>Invoke-Restmethod -uri
'https://ci.appveyor.com/api/builds' -Headers $headers -Method Post
-Body $body</code></p>
<p>(ie with a non-json body) and this worked and successfully
triggered a build!</p>
<p>Is there a bug here or am I doing something else wrong ?
(Although I'm happy to have triggered the build).</p></div>scascarinitag:help.appveyor.com,2012-11-13:Comment/332207952014-07-04T09:06:30Z2014-07-04T09:06:30ZTrigger a Build<div><p>The latter is correct - <code>-Body</code> parameter must be an
object, not a string (<a href=
"http://technet.microsoft.com/en-us/library/hh849971.aspx">http://technet.microsoft.com/en-us/library/hh849971.aspx</a>).</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/332207952014-07-04T10:03:58Z2014-07-04T10:04:57ZTrigger a Build<div><p>Invoke-Restmethod happily sends the body as Json (checked with
Fiddler). My query was really that I read your comment (#2) above
as the body having to be json rather than name value pairs.</p>
<p>On reflection I tried setting the content type correctly (!)</p>
<p><code>Invoke-Restmethod -uri
'https://ci.appveyor.com/api/builds' -Headers $headers -Method Post
-Body $bodyAsjson -ContentType "application/json"</code></p>
<p>and that works. So that's all good.</p>
<p>If I leave the Content Type as the default
(application/x-www-form-urlencoded) it also works with name value
pairs</p>
<p><code>Invoke-Restmethod -uri
'https://ci.appveyor.com/api/builds' -Headers $headers -Method Post
-Body $body</code></p></div>scascarinitag:help.appveyor.com,2012-11-13:Comment/332207952014-07-04T10:11:51Z2014-07-04T10:11:51ZTrigger a Build<div><p>I see, thanks for your notes.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/332207952014-08-07T14:37:17Z2014-08-07T14:37:17ZTrigger a Build<div><p>Great Topic, Great Feature.</p></div>Rifat Erdem Sahintag:help.appveyor.com,2012-11-13:Comment/332207952014-08-08T07:17:06Z2014-08-08T07:17:06ZTrigger a Build<div><p>Script to copy paste</p>
<hr>
<p>$token = 'write_your_token_here' $headers = @{ "Authorization" =
"Bearer $token"} $body = @{accountName = "write_your_account_name";
projectSlug = "write_your_project_name"} $bodyAsJson = $body |
ConvertTo-json Invoke-Restmethod -uri '<a href=
"https://ci.appveyor.com/api/builds&#39">https://ci.appveyor.com/api/builds&#39</a>;
-Headers $headers -Method Post -Body $bodyAsjson -ContentType
"application/json"</p>
<hr></div>Rifat Erdem Sahintag:help.appveyor.com,2012-11-13:Comment/332207952015-03-11T15:11:22Z2015-03-11T15:11:22ZTrigger a Build<div><p>Hello,</p>
<p>We want to run our acceptance test project after deployment
completes. While AWS Elasticbeanstalk needs 3-5 minutes to
propagate the deployment.</p>
<p>Is it possible to postpone trigger to run X minutes after
initial build completes?</p>
<p>Thanks,<br>
Kerem</p></div>keremtag:help.appveyor.com,2012-11-13:Comment/332207952015-03-11T16:55:45Z2015-03-11T16:55:45ZTrigger a Build<div><p>There is no such ability right now. You could develop some kind
of "buffering" service with delay inside or using Service Bus -
just few ideas.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/332207952015-09-25T21:33:41Z2015-09-25T21:33:41ZTrigger a Build<div><p>Hello Feodor,</p>
<p>I'm trying to trigger another project to make deployment to aws
elastic beanstalk. I have the scripts ready but cannot post proper
parameters and catch from the project I triggered.</p>
<p>I need path to two of the artifacts to be post and referenced
from other project. Can you help me with the ps script?</p>
<p>Thanks,<br>
Kerem</p></div>keremtag:help.appveyor.com,2012-11-13:Comment/332207952015-09-25T21:43:29Z2015-09-25T21:43:29ZTrigger a Build<div><p>Here you are. We've added some helper methods to call other
project builds and download artifacts.</p>
<p>This is how to start a new build of another "deployment"
project: <a href="https://github.com/appveyor/simple-web/blob/master/appveyor.yml#L20-L21">
https://github.com/appveyor/simple-web/blob/master/appveyor.yml#L20...</a></p>
<p>This is the "deployment" project downloading artifacts from
first project and deploying them with selected method: <a href="https://github.com/FeodorFitsner/deploy-project/blob/master/appveyor.yml">
https://github.com/FeodorFitsner/deploy-project/blob/master/appveyo...</a></p>
<p>Let me know if you have any questions.</p></div>Feodor Fitsner