If you need to setup a cross project trigger from Cloud Source Repository (aka CSR) to Cloud Build (aka CB), one way could be this one:
# this is the project containing the Cloud Source Repository
export PROJECT_CSR=my-csr-project
export CSR_REPO_NAME=my-repo
# this is the project running Cloud Build Job
export PROJECT_CB=my-cb-project
gcloud pubsub topics create projects/$PROJECT_CSR/topics/$CSR_REPO_NAME
gcloud source repos update $CSR_REPO_NAME --add-topic=$CSR_REPO_NAME
Note: the CB service need to be already enabled on the project otherwise the service account will not be present
CB_SA=$(gcloud projects get-iam-policy $PROJECT_CB --flatten="bindings[].members" --filter='bindings.members:*@gcp-sa-cloudbuild.iam.gserviceaccount.com' --filter='bindings.role:roles/cloudbuild.serviceAgent' --format='value(bindings.members)')
now you should have the variable '$CB_SA' with the name of the CB service account agent present.
this is needed to allow CB to subscribe the topic where CSR will push notifications
gcloud projects add-iam-policy-binding $PROJECT_CSR \
--member serviceAccount:$CB_SA \
--role=roles/pubsub.subscriber
this is needed to allow CB to pull code from the target repository
gcloud projects add-iam-policy-binding $PROJECT_CSR \
--member serviceAccount:$CB_SA \
--role=roles/source.reader
In this example I'm using inline config file (cloudbuild-test.yaml) but you should adapt it based on your target.
gcloud builds triggers create pubsub \
--name=$CSR_REPO_NAME \
--topic=projects/$PROJECT_CSR/topics/$CSR_REPO_NAME \
--region=global \
--inline-config=./cloudbuild-test.yaml \
--repo=https://source.developers.google.com/p/$PROJECT_CSR/r/$CSR_REPO_NAME \
--repo-type=CLOUD_SOURCE_REPOSITORIES \
--branch=master
Now you should be able to trigger a CB job on a code change pushed on the CSR repo.