te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>c# - From Pipeline How To Pass the value to GetEnvironmentVariable - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - From Pipeline How To Pass the value to GetEnvironmentVariable - Stack Overflow

programmeradmin3浏览0评论

I have this code in the program.cs file - how to pass the value from the Azure pipeline to the TANKDEV_ENV?

string environment = Environment.GetEnvironmentVariable("TANKDEV_ENV") ?? "Development";

Pass the STG or production or development from the pipeline

I have this code in the program.cs file - how to pass the value from the Azure pipeline to the TANKDEV_ENV?

string environment = Environment.GetEnvironmentVariable("TANKDEV_ENV") ?? "Development";

Pass the STG or production or development from the pipeline

Share Improve this question edited 2 days ago marc_s 755k184 gold badges1.4k silver badges1.5k bronze badges asked 2 days ago AlgoXperience -TamilAlgoXperience -Tamil 11 silver badge New contributor AlgoXperience -Tamil is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 2
  • 1 I've removed the irrelevant tags from your question. Please be mindful of the tags you're using and if they have any bearing on the specific question you're asking. – ProgrammingLlama Commented 2 days ago
  • I've not used Azure Pipelines, so I'm not sure if these docs are useful: learn.microsoft/en-us/azure/devops/pipelines/process/… – ProgrammingLlama Commented 2 days ago
Add a comment  | 

1 Answer 1

Reset to default 2

You can use pipeline variables to pass values as environment variables into the C# app when executing the C# App in pipleine. In pipleine, the normal pipeline variables (not secret variables) will be automatically decrypted into environment variables. So, you can define some normal pipeline variables with the values you want to pass from pipleine into the C# app.

See below example as reference:

  1. The C# code (a Console App).
var my_var01 = Environment.GetEnvironmentVariable("MY_VAR01", EnvironmentVariableTarget.Process);
var my_var02 = Environment.GetEnvironmentVariable("MY_VAR02", EnvironmentVariableTarget.Process);
var my_var03 = Environment.GetEnvironmentVariable("MY_VAR03", EnvironmentVariableTarget.Process);
var my_var04 = Environment.GetEnvironmentVariable("MY_VAR04", EnvironmentVariableTarget.Process);
Console.WriteLine($"my_var01 = {my_var01}.");
Console.WriteLine($"my_var02 = {my_var02}.");
Console.WriteLine($"my_var03 = {my_var03}.");
Console.WriteLine($"my_var04 = {my_var04}.");

  1. The pipeline (azure-pipelines.yml).
. . .

# Global pipeline variables.
# Can be available for all stages, jobs and tasks within current pipeline.
variables:
  my_var01: 'VarValue01'  # The environment variable 'MY_VAR01' is automatically mapped for it.

stages:
- stage: Stage1
  # Stage-level pipeline variables.
  # Can be available for all jobs and tasks within current stage.
  variables:
    my_var02: 'VarValue02'  # The environment variable 'MY_VAR02' is automatically mapped for it.
  jobs:
  - job: JobA
    # Job-level pipeline variables.
    # Can be available for all tasks within current job.
    variables:
      my_var03: 'VarValue03'  # The environment variable 'MY_VAR03' is automatically mapped for it.
    steps:
    # Set pipeline variable when running the task.
    # Can be available for all the susequent tasks within current job.
    # The environment variable 'MY_VAR04' is automatically mapped for 'my_var04'.
    - pwsh: |
        $getValue = "VarValue04"
        Write-Host "##vso[task.setvariable variable=my_var04;]$getValue"
      displayName: 'Set Variable'
    
    - task: DotNetCoreCLI@2
      displayName: 'Build App'
      inputs:
        command: 'publish'
        publishWebProjects: false
        projects: 'RetrieveEnv/RetrieveEnv.csproj'
        arguments: '-c $(BuildConfiguration) -o $(Build.ArtifactStagingDirectory)'
        zipAfterPublish: false

    - task: DotNetCoreCLI@2
      displayName: 'Execute App'
      inputs:
        command: 'custom'
        custom: '$(Build.ArtifactStagingDirectory)/RetrieveEnv/RetrieveEnv.dll'

If the values you want to pass into the C# app are static/fixed and will not be changed often, you can use the values to define some static pipeline variables, just like as the variable my_var01, my_var02 or my_var03 in above example.

If the values are generated/fetched during running the pipeline, for example, when you run some command lines on the script task to output some values, you can use the logging command SetVariable to set variables with the fetched values. Just like as the variable my_var04 in above example.


发布评论

评论列表(0)

  1. 暂无评论