Skip to main content

nerdbank_gitversioning/cloud_build_services/
bitbucket_cloud.rs

1// Copyright (c) .NET Foundation and Contributors. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4//! [Bitbucket Cloud](https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/) support.
5
6use std::io::{self, Write};
7
8use crate::cloud::{CloudBuild, EnvironmentVariables, empty_variables, env, should_start_with};
9
10/// Bitbucket Cloud Pipelines integration.
11pub struct BitbucketCloud;
12
13impl CloudBuild for BitbucketCloud {
14    fn name(&self) -> &'static str {
15        "BitbucketCloud"
16    }
17
18    fn is_applicable(&self) -> bool {
19        [
20            "BITBUCKET_PIPELINE_UUID",
21            "BITBUCKET_STEP_UUID",
22            "BITBUCKET_STEP_TRIGGERER_UUID",
23        ]
24        .into_iter()
25        .all(|name| env(name).is_some_and(|value| !value.trim().is_empty()))
26    }
27
28    fn is_pull_request(&self) -> bool {
29        env("BITBUCKET_PR_ID").is_some_and(|value| !value.trim().is_empty())
30    }
31
32    fn building_branch(&self) -> Option<String> {
33        should_start_with(env("BITBUCKET_BRANCH"), "refs/heads/")
34    }
35
36    fn building_tag(&self) -> Option<String> {
37        should_start_with(env("BITBUCKET_TAG"), "refs/tags/")
38    }
39
40    fn git_commit_id(&self) -> Option<String> {
41        env("BITBUCKET_COMMIT")
42    }
43
44    fn set_cloud_build_number(
45        &self,
46        _build_number: &str,
47        _stdout: &mut dyn Write,
48        _stderr: &mut dyn Write,
49    ) -> io::Result<EnvironmentVariables> {
50        Ok(empty_variables())
51    }
52
53    fn set_cloud_build_variable(
54        &self,
55        _name: &str,
56        _value: &str,
57        _stdout: &mut dyn Write,
58        _stderr: &mut dyn Write,
59    ) -> io::Result<EnvironmentVariables> {
60        Ok(empty_variables())
61    }
62}