Unable to get latest build for repo

Hi, I have a trigger set to start build for a downstream project and my trigger in the parent project is throwing this error
Error: unable to get latest build for <xyz_repo>

trigger looks like this
trigger:
image: plugins/downstream
server: link_to_drone_server
fork: true
secrets: [TOKEN]
token: $TOKEN
when:
event: push
branch: some-branch
success: true
repositories:
- xyz_repo

I am not able to find any answer for this on google or on drone discussions. Did anyone else encounter such issue ?

This is likely an authentication issue. I recommend reading our troubleshooting guide for using secrets, which highlights some common configuration mistakes http://docs.drone.io/secrets-not-working/

There are two issues that I think need to be address:

First this is not valid syntax. You cannot set a yaml attribute to an environment variable using dollar sign syntax.

Second plugins expects the secret to have very specific names. In this case, the dowstream plugin will look for a variable named DOWNSTREAM_TOKEN

This would result in the following change to your yaml, assuming you re-name your secret:

-secrets: [TOKEN]
-token: $TOKEN
+secrets: [DOWNSTREAM_TOKEN]

Note that if you do not want to rename your secret, drone supports secret aliasing, so that you can convert the secret to the expected name at runtime:

-secrets: [TOKEN]
-token: $TOKEN
+secrets:
+  - source: TOKEN
+    target: DOWNSTREAM_TOKEN

In your example the repository name is xyz_repository. Can you confirm you are using the correct repository name format, which is {owner}/{name}, for example octocat/hello-world

If you continue to experience issues, please following the usage instructions in the plugin repository to manually test your configuration from the command line. This can help you find and resolve any issues. https://github.com/drone-plugins/drone-downstream#usage

Also please consider stepping through the code, if needed.

The plugin is working (I just tried it) so it is likely a configuration issue.

Hi Brad,
Can {owner}/{name} have special characters like (underscore)’_’ and (hyphen)’-’ ? I have tried using drone-cli as well to set the drone_token. Cross checked with the drone-downstream plugin usage as well. The error still persists.

Thanks,
Sid

Absolutely, here is an example I just ran using the CLI

$ drone build last drone/drone-cli
Number: 138
Status: success
Event: push
Commit: f8ac218c04671484d68d32e4139188f991f2fbd8
Branch: master
Ref: refs/heads/master
Message: update drone-go vendor
Author: bradrydzewski

In fact, the majority of my projects (virtually every plugin) has an underscore or dash in the title.

Error: unable to get latest build for <xyz_repo>

This is the line of code causing the error:

// get the latest build for the specified repository
build, err := client.BuildLast(owner, name, branch)
if err != nil {
	return fmt.Errorf("Error: unable to get latest build for %s.\n", entry)
}

Please note that trigger plugin re-launches an existing build, optionally with a new build number. This error tells me that it cannot find an existing build for your repository and branch.

Hey Brad,
Thanks for the prompt response. I just got it to work :relieved: .
What I found out with the changed that I made to the drone config was fork option is not working. The moment I removed the fork option the project kicked the downstream project. Also, there was no issue with the repo location. Somehow, fork was the culprit. My final trigger looks like this:
trigger:
image: plugins/downstream
server: link_to_drone_server
secrets: [DOWNSTREAM_TOKEN]
when:
event: push
branch: some-branch
success: true
repositories:
- xyz-repo/some_project

Thanks for the helpful resources,
Sid

@bradrydzewski : Is the fork option working for downstream plugin ?

To my knowlege. I recommend looking at the source code and submitting a patch if you think there is an issue.

@bradrydzewski @sidhjhawar Hey Guys, I am also facing the same issue and tried the same configuration mentioned by @sidhjhawar, but still getting the “Error: unable to get latest build for **”

Here are my settings in .drone.yml

trigger:
image: plugins/downstream
server: ci.drone.com
repositories:
- abc/abc
secrets: [ DOWNSTREAM_TOKEN ]
token: $DOWNSTREAM_TOKEN
when:
event: push
branch: master
success: true

@agtenfold the syntax in your example yaml configuration is invalid.

 secrets: [ DOWNSTREAM_TOKEN ]
-token: $DOWNSTREAM_TOKEN

I tried with all possible combinations. I have already tried with the following, and without token as well.

secrets: [ DOWNSTREAM_TOKEN ]
token: [ DOWNSTREAM_TOKEN ]

@agtenfold that is still not the correct format. If you provide the token as a secret, you should not set the token value in the yaml.

Reference http://plugins.drone.io/drone-plugins/drone-downstream/#secret-reference

If I just used secrets: [ DOWNSTREAM_TOKEN ] then I get the error, saying Please provide drone access token.

saying Please provide drone access token.

This indicates the secret is not being passed into the plugin. This happens when the secret is not properly added to Drone or not properly configured. Please see the following documentation for debugging issues with secrets: